在我的代码中,我使用txt文件包含的向量解析txt文件:
111|01-11111|TVNX0020430301519114|A45N9|Lions Gate Entertainment|Redemption 2013 HD|$5.99|2014-01-23T12:55|WATVC|35555|0003E6420F88|STB|
我想将这些数据写入Excel。通过使用向量我解析的是代码:
vector< vector<string> > data;
void parse(const char* name)
{
ifstream in(name);
string line;
// read the file
while ( getline(in,line,'|') )
{
vector<string> fields;
std::stringstream linestream(line);
for ( int col = 0 ; col < 21 ; col++ )
{
string f;
linestream >> f;
fields.push_back(f);
fields.erase(std::remove_if(fields.begin(), fields.end(), isspace),fields.end());
}
data.push_back(fields);
}
for ( vector< vector<string> >::size_type row = 0 ; row < data.size() ; row++ )
{
for ( vector<string>::size_type col = 0 ; col < data[row].size() ; col++ )
{
cout << data[row][col];
}
cout << endl;
}
}
我想只分开管道和&#34; \ n&#34;我不想将字符串与空格分开,因此我可以将完整的字符串写入一个标题。
我用来忽略空格擦除
fields.erase(std::remove_if(fields.begin(), fields.end(), isspace),fields.end());
它给出了错误:
error C2664: 'int (int)' : cannot convert parameter 1 from 'std::basic_string<_Elem,_Traits,_Ax>' to 'int'
with
[
_Elem=char,
_Traits=std::char_traits,
_Ax=std::allocator
]
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called