从C ++中的字符串中删除双引号 [英] remove double quotes from a string in c++
问题描述
我正在从字符串中去除双引号,但是我不断从以下函数中收到此错误。这里的问题是什么?
I am stripping off double quotes from a string, but I keep getting this error from the following function. What is the problem here?
void readCSVCell(stringstream& lineStream, string& s) {
std::getline(lineStream,s,',');
s.erase(remove( s.begin(), s.end(), '\"' ), s.end());
}
[错误]
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>>>
到<$ c $为参数1
到int remove(const char *)
的c> const char * / p>
c.cpp: In function
void readCSVCell(std::stringstream&, std::string&)
:
c.cpp:11: error: cannot convert__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >
toconst char*
for argument1
toint remove(const char*)
推荐答案
您不想要这样的东西:
s.erase(remove( s.begin(), s.end(), '\"' ),s.end());
由于 remove
返回前向迭代器指向到序列的新末端,该序列现在包括所有具有除value以外的值的元素,而不是删除这些值。
As remove
returns "A forward iterator pointing to the new end of the sequence, which now includes all the elements with a value other than value" rather than removing the values.
尽管如此,它对我来说编译起来还不错gcc 4.4),所以也许您只需要包含< algorithm>
并确保您正在使用命名空间std
或限定名称。
It compiles fine for me though (with gcc 4.4), so perhaps you just need to include <algorithm>
and make sure you are either using namespace std
or qualify the name.
这篇关于从C ++中的字符串中删除双引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!