【发布时间】:2015-03-30 12:43:15
【问题描述】:
有人可以向我解释如何正确搜索存储在字符串类中的“制表符”字符吗?
例如:
text.txt 内容:
std::cout << "Hello"; // contains one tab space
用户在提示符下输入:./a.out
main.cpp:
string arrey;
getline(cin, arrey);
int i = 0;
while( i != 10){
if(arrey[i] == "\t") // error here
{
std::cout << "I found a tab!!!!"
}
i++;
}
由于文本文件中只有一个制表符空间,我假设它存储在索引 [0] 中,但问题是我似乎无法进行比较,而且我不知道任何其他方式搜索它。有人可以帮忙解释一下替代方案吗?
Error: ISO C++ forbids comparison between pointer and integer
【问题讨论】:
-
if(arrey[i] == '\t')
标签: c++