64,647
社区成员
发帖
与我相关
我的任务
分享
string message;
ifstream file;
file.open("myfile.txt");
if(file.is_open()) //文件打开成功,说明曾经写入过东西
{
while(file.good() && !file.eof())
{
memset(buf,0,1024);
file.getline(buf,1204);
message = buf;
...... //这里可能对message做一些操作
cout< }
file.close();
}
int main()
{
printf("test insert code");
}
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream istrm("./test.txt", ios::in);
if (istrm) //open succeed
{
string line;
while (getline(istrm, line))
{
cout<<line<<endl;
}
}
else
{
cerr<<"open failed"<<endl;
}
return 0;
}