我試圖將4個字符串放入使用for循環的數組中。之後爲循環完成,我試圖顯示使用for循環的4個字符串。我不知道我的錯誤在哪裏。任何幫助和指導,將不勝感激。C++數組,For循環和字符串數據類型
#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
謝謝。我做了修改,但是我仍然遇到錯誤。 – pHorseSpec 2014-10-29 03:28:41
@ user3708219爲了將來的參考,最好指定錯誤。這樣可以幫助我們縮小問題的範圍。 – 0x499602D2 2014-10-29 03:30:05
@ user3708219錯誤是什麼? – 0x499602D2 2014-10-29 03:31:09