txt中以一段数据是 1\t2\t3\r\n
如果是1,2,3形式我会读取,但是出现转义字符再用if(ch=‘,’)infile>>a>>ch;的形式‘\t’就不可以了,怎么解决啊
这个应该可以满足你,用getline读取,然后按照分隔符分割,有什么阻碍的你就在 isNeed 函数里的 switch 里面添加条件就好了
#include <iostream>可是我要读的数据有好多行,要是一个一个读有些麻烦。
有没有其他的办法呢?
用getline呢。
#include
#include
#include
using namespace std;
int main()
{
string tmp;
string content;
fstream fs("d:\\1.txt");
while( getline(fs,tmp) ){
content+=tmp;
content+="\n";
}
cout << content << endl;
return 0;
}