【发布时间】:2023-03-23 08:49:01
【问题描述】:
我正在尝试使用 for 循环将 4 个字符串放入一个数组中。在 for 循环完成后,我尝试使用 for 循环显示 4 个字符串。我不知道我的错误在哪里。任何帮助和指导将不胜感激。
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main()
{
//declare variables
string array[4] ;
cout<<"input 4 strings"<<endl;
for (int i=1; i<4; i++)
{
getline(cin,array[i]);
}
cout << "here are your 4 strings" << endl;
for (int j=0; j<4; j++)
{
cout<<array[j]<<endl;
}
system("pause");
return 0;
} // end of main function
【问题讨论】:
标签: c++ arrays string for-loop