プログラムの利用者が書いた文章のすべての文字を分析するプログラムを作りたい。たとえば、誰かが「こんにちは」と入力します。これらすべての文字をいくつかの配列に配置する方法はありますか?たとえば、myArray [0] = h、myArray [1] = e、...ありがとうございます
質問する
707 次
1 に答える
6
配列と同じように使用できます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
を参照してください。
于 2012-07-22T15:58:15.797 に答える