Learn C++ Online

Basic input/output

On this page
This lesson contains approximately 25 minutes of video content.

Basic input/output

Writing to standard out and to files

Reading from standard in and from files

Q1

QQ1

This question is ungraded.

Given an input file stream ifs, what would you ask the stream object (e.g., ifs.what()) to inquire whether the stream is successfully bound to a file?

Q2

QQ2

This question is ungraded.

True or false? Formatted reads are whitespace delimited.

Q3

QQ3

This question is ungraded.

Assume that the file aggieland.txt is composed as follows:

Century Tree
After the following code snippet has been executed,
std::ifstream ifs{"aggieland.txt"};
std::string str;
ifs >> str;
what value is stored in str?

Q4

QQ4

This question is ungraded.

Assume that the file football.txt is composed as follows:

the 12th Man
After the following code snippet has been executed,
std::ifstream ifs{"football.txt"};
std::string read1;
int read2;
ifs >> read1 >> read2;
what value is stored in read2?

Q5

QQ5

This question is ungraded.

If you would like to append to an existing file, you must specify this intention, otherwise the file will be overwritten. From the lesson, you must specify   as the second argument in constructing the std::ofstream. Hint: your response should start with std::.