分析用户输入c++

analyze user input c++

本文关键字:c++ 输入 用户      更新时间:2023-10-16

我想制作一个程序,分析程序用户编写的文本中的每个字母。例如,有人键入"你好"。有没有办法把所有这些字母放在一个数组里?例如,myArray[0]=h,myArray[1]=e,。。。感谢

您可以像使用数组一样使用std::string,但它是动态的,知道它的大小,而且更灵活。

//string is like a dynamic array of characters
std::string input; 
//get a whole line of input from stdin and store it
std::getline (std::cin, input); 
//you can manipulate it like an array, among other things
input [0] = 'i'; //now "iello there"

有关std::string的完整参考,请参阅此处。