我想制作程序,分析程序用户编写的文本的每个字母.例如,某人键入"你好".有没有办法将所有这些字母放在某个数组中?例如,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"
Run Code Online (Sandbox Code Playgroud)
有关完整参考std::string,请参见此处.
| 归档时间: |
|
| 查看次数: |
572 次 |
| 最近记录: |