Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个字符串“s”,我想通过开始一个乞求(位置 0)来获得一个子字符串,并以一个空格结尾 - 这样如果有人要输入他们的全名,我可以确定他们的名字。
我可以发誓他们是一个子字符串函数,可以“搜索”直到找到某个字符。提前致谢!
像这样的东西会起作用:
#include <string> #include <iostream> int main() { std::string str = "Person Name"; size_t pos = str.find(" "); std::cout << str.substr(0,pos); }