in C++ ¶
~cpp #include <fstream> using namespace std; int main() { ifstream fin("input.txt"); // fin과 input.txt를 결 ofstream fout("output.txt"); // fout과 output.txt를 결 int a,b; fin >> a >> b; // cin로 면 력는다면, fin 결된 로부 력는다. fout << a+b << endl; // cout로 면로 력다면, fout 결된 output.txt a+b를 력 return 0; }
~cpp 3 8
Python ¶
~cpp fin = file('input.txt') fout = file('output.txt.','w') a,b=[int(i) for i in fin.read().split()] print >> fout,(a+b) # fout.writeline( str(a+b)+'n' ) fin.close() fout.close()
~cpp 3 8
Java ¶
~cpp try { String inputString; InputStreamReader isr = new InputStreamReader(new FileInputStream(fileName)); BufferedReader br = new BufferedReader(isr); while((inputString = br.readLine()) != null) { buf = buf + inputString ; buf = buf + "r" ; buf = buf + "n" ; {} br.close(); } catch (IOException e) System.out.println("Error : "+ e.toString()); {}