【发布时间】:2012-03-06 01:32:34
【问题描述】:
我有一个字符串,该字符串包含例如“Hello\nThis is a test.\n”。
我想在字符串中的每个 \n 上拆分整个字符串。我已经编写了这段代码:
vector<string> inData = "Hello\nThis is a test.\n";
for ( int i = 0; i < (int)inData.length(); i++ )
{
if(inData.at(i) == "\n")
{
}
}
但是当我编译这个时,我得到一个错误: (\n 作为字符串)
binary '==' : no operator found which takes a left-hand operand of type 'char' (or there is no acceptable conversion)
(以上代码)
'==' : no conversion from 'const char *' to 'int'
'==' : 'int' differs in levels of indirection from 'const char [2]'
问题是我无法查看 char 是否等于“新行”。我该怎么做?
【问题讨论】:
-
你确定你的意思是成为
vector<string>?
标签: c++ windows char newline equals