use*_*215 2 c++ string double-quotes
我正在从字符串中删除双引号,但我不断从以下函数中得到此错误.这里有什么问题?
void readCSVCell(stringstream& lineStream, string& s) {
std::getline(lineStream,s,',');
s.erase(remove( s.begin(), s.end(), '\"' ), s.end());
}
Run Code Online (Sandbox Code Playgroud)
[错误]
c.cpp:在功能
void readCSVCell(std::stringstream&, std::string&):
c.cpp:11:错误:无法转换__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >到const char*的参数1来int remove(const char*)
你不想要这样的东西:
s.erase(remove( s.begin(), s.end(), '\"' ),s.end());
Run Code Online (Sandbox Code Playgroud)
作为remove回报"的正向迭代器指向序列,其现在包括所有具有比值以外的值的元素的新的结束",而不是移除值.
虽然它对我来说很好(使用gcc 4.4),所以也许你只需要包括<algorithm>并确保你是using namespace std或者限定名称.
| 归档时间: |
|
| 查看次数: |
10968 次 |
| 最近记录: |