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()); {}









