#gesp4w25. 2025GESP四级 文件操作
2025GESP四级 文件操作
2025GESP四级 文件操作
2503真题
1.(2503-15)下面哪种方式不能实现将字符串 "Happy Spring!" 输出重定向到文件 log.txt ( )?
{{ select(1) }}
-
freopen("log.txt", "w", stdout); cout << "Happy Spring!" << endl; fclose(stdout); -
std::ofstream outFile("log.txt"); outFile << "Happy Spring!" << endl; outFile.close(); -
std::ofstream outFile("log.txt"); cout << "Happy Spring!" << endl; outFile.close(); -
std::ofstream outFile("log.txt"); cout << "Happy Spring!" << endl; outFile.close();
2506真题
2.(2506-13)关于下面 C++ 程序的描述,( )最准确。
ifstream in("data.txt");
string line;
while (getline(in, line)) {
cout << line << endl;
}
{{ select(2) }}
- 将从标准输入读取每行,并输出到屏幕
- 程序无法运行,因为 getline 只能读取 cin
- 将 data.txt 中的每一行读取并输出到屏幕
- 程序将创建 data.txt 并写入默认文本
2509真题
无
2512真题
3.(2512-14)执行下面 C++ 程序,会输出( )?
int main() {
ofstream fout("test.txt");
fout << "Happy" << endl;
fout << "New Year";
fout.close();
ifstream fin("test.txt");
string s1, s2;
fin >> s1;
getline(fin, s2);
fin.close();
cout << s1 << "|" << s2;
return 0;
}
{{ select(3) }}
- Happy|New Year
- Happy| New Year
- HappyNew Year|
- Happy|