分割用户在参数中输入的字符串
Split a string entered by the user in arguments
如何分割用户在参数中输入的字符串?
假设用户类型为test1 test2 test3
如何将每个输入的值分开,以使我可以分别访问这些值?
使用getline和stringstream从用户输入中提取字符,并将它们存储到字符串中,直到您通知的定界。依次使用vector存储提取的字符。
像这样:
void split(std::vector<std::string> &args, std::string userInput, char delimiter)
{
std::stringstream ss(userInput);
std::string buf;
while(getline(ss, buf, delimiter)) {
args.push_back(buf);
}
}
相关文章:
- C++,在int数组中输入字符串或字符会输出0,而不是ascii或error
- 用户输入字符串的文件附加问题..C++
- 从 cin 读取不会返回整个输入字符串
- 输出返回编号。等于输入字符串的单词的字符串数
- 控制台未正确读取输入字符串
- 使用终止程序的指针在数组中输入字符串
- 如何删除用户输入字符串末尾的空字符?
- 在循环中使用 cin.get() 输入字符串
- 如何从输入字符串中提取特定位置的字符?
- 用户输入字符串的结构的搜索向量
- 无法使用 getline() 输入字符串.它只读取一个字符串
- 如何在 c++ 中读取输入字符串,忽略空格
- FSTREAM的问题读取确定,但不编写用户输入字符串
- boost::split会在输入字符串不是常量时更改输入字符串吗?
- 通过键盘输入字符串数组和 int 数组的数组大小
- Zlib 放气输入大于原始输入字符串的字符
- C 忽略输入字符串
- 获取一个输入字符串,将其转换为其十六进制值,然后将其十六进制存储为 int
- 我无法将 Excel 中的输入字符串存储为二维字符串
- 如何识别输入的输入字符串在 c++ 中是两个还是多个单词