出现的问题
1.未使用using namespace std导致ofstream不能初始化
#include<fstream>
#include<iostream>
using namespace std;//为输入该行导致ofstream无法识别
void output()
{
ofstream text;
text.open("text.txt", ios::out);
text << "写入操作" << endl;
text.close();
}
void read()
{
ifstream text;
text.open("text.txt", ios::in);
char s[100] = {0};
while (text >> s)
{
cout << s << endl;
}
text.close();
}
int main()
{
output();
read();
system("pause");
}
概念链接