st11-file

st11-file - 3 data per line 1 st data an integer 2 nd data...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
1 CSC 1111 Introduction to Computing using C++ File I/O (Self-test questions)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 What's the output? ofstream fout("test.dat"); fout << "Hello"; fout.close(); fout.open("test.dat"); fout.close(); What will the file "test.dat" contain?
Background image of page 2
3 What's the output? char ch; ifstream fin("input.txt"); while (!fin.eof()) { fin >> ch; cout << ch << endl; } fin.close(); What's the output? 1 23 4 A 5 Content of file "input.txt"
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 What's the output? char ch = 'X'; int x; ifstream fin("input.txt"); while (!fin.eof()) { fin >> x; if (fin.fail()) { fin >> ch; cout << ch << endl; } else cout << x << endl; } fin.close(); What's the output? 1 23 4 A 5 Content of file "input.txt"
Background image of page 4
5 Reading data from file How can you read data from a file with the following format? 3 data per line 1 st data: an integer 2 nd data: a real number 3 rd data: A string containing no whitespace characters. 1234 10.0 XYZ1234 2345 11.0 ABC0001
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 Reading data from file How can you read data from a file with the following format?
Background image of page 6
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 8
Background image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 3 data per line 1 st data: an integer 2 nd data: a real number 3 rd data: a name (a string which may contain spaces) 1234 10.0 Steve Mark 2345 11.0 Tai Man Chan … 7 Reading data from file How can you read data from a file with the following format? Morse codes separated by space or newline characters Each code is represented by a string containing only '-' and ' . ' characters.-.-- --.- ---- -.-. .-.---. .. . ..--.- --.--8 Reading data from file How can you read data from a file with the following format? 4 integers per line. Each integer is separated from one another by a comma. 10,20,30,40 1,2,3,4 … 9 Reading data from file How can you read data from a file with the following format? One or more integers per line. Each integer is separated from one another by a comma. 10,20,30,40,50,60,70 10 1,2,3,4 …...
View Full Document

This note was uploaded on 12/28/2010 for the course CSC CSC1110 taught by Professor Cjyuan during the Fall '06 term at CUHK.

Page1 / 9

st11-file - 3 data per line 1 st data an integer 2 nd data...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online