#include<iostream>
#include <string>
#include<fstream>
using namespace std;void main()
{
ifstream fin("a.dat");
string s; if (fin==NULL)
{
cout<<"ERROR"<<endl;
}
while (getline(fin,s))
{
cout<<s<<endl;
}
}
这些代码把dat文件中的字符串全部加载 我想成行加载或用空格分开加载该怎么写?
#include <string>
#include<fstream>
using namespace std;void main()
{
ifstream fin("a.dat");
string s; if (fin==NULL)
{
cout<<"ERROR"<<endl;
}
while (getline(fin,s))
{
cout<<s<<endl;
}
}
这些代码把dat文件中的字符串全部加载 我想成行加载或用空格分开加载该怎么写?
while (getline(fin,s)) //这个就是用空格分开加载 get()一个一个读取,找到空格后,完成一次读取。