<分区>
好的。所以我正在制作一个简单的程序来试验字符串,并且在程序的一部分中,一个 for
循环按顺序垂直显示字符串的每个字母。我正常运行该程序以检查其在整个编码过程中的进度,但是当我将其放入时,发生了错误。这是我的代码:
int main()
{
std::string word1 = "Chicken";
std::string word2("Nuggets");
std::string word3(3, '!');
std::string phrase = word1 + " " + word2 + word3;
std::cout << "The phrase is: " << phrase << "\n\n";
std::cout << "This phrase has " << phrase.size() << " letters!" << "\n\n";
std::cout << "The character at position zero is " << phrase[0] << "\n\n";
phrase[0] = 'S';
std::cout << "The phrase is now... " << phrase << "\n\n";
for (unsigned int i = 0; i <= phrase.size(); ++i)
{
std::cout << "Position " << i << "'s character is " << phrase[i] << "\n";
}
}
非常感谢任何帮助,以及对我的代码的反馈(因为我是新手)。
附言<iostream>
和 <string>
包括在内,我只是无法在
上向您展示它
网站。对不起!