E D R , A S I H C RSS

File Input Output

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;
}

input.txt
~cpp 
3 8

 € ”„๋กœธ๋žจ„ ‹–‰•˜๋ฉด output.txtฐ€ ƒธฐ๋ฉด„œ 11•ˆ— จ„‹ค.

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()

input.txt
~cpp 
3 8

 € ”„๋กœธ๋žจ„ ‹–‰•˜๋ฉด output.txtฐ€ ƒธฐ๋ฉด„œ 11•ˆ— จ„‹ค.

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()); {}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:16
Processing time 0.0082 sec