本文介绍了string.find("")未找到空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在用户输入的字符串中找到空格。我想使用 find()
从 std :: string
返回空格的位置。
I'm trying to find space in a string that a user inputs. I want to use find()
from std::string
to return the position of the space.
如果输入为Seattle,WA USA,我想要 find(,0)
return 8
,我该怎么做? 8th是,之后的空格。
If the input is "Seattle, WA USA", and I want find(" ", 0)
to return 8
, how would I do this? 8th is the space after ","
string inputString = " ";
cout << "Enter String to modify" << endl;
cin >> inputString;
int spac = inputString.find(" " , 0);
但是 find()
code> 0 。
我不知道为什么。
But find()
is keep returning 0
.I am not sure why.
推荐答案
你不是在读空间( cin
You're not reading the space (cin >> inputString
stops on whitespace...).
使用 std :: getline(std ::>>< cin,inputString)
。
这篇关于string.find("")未找到空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!