我怎样才能让这个程序的输出正常工作?我不知道为什么字符串数组不会存储我的值,然后在我的程序结束时输出它们。谢谢。字符串数组输出
#include <iostream>
#include <string>
using namespace std;
int main()
{
int score[100], score1 = -1;
string word[100];
do
{
score1 = score1 + 1;
cout << "Please enter a score (-1 to stop): ";
cin >> score[score1];
}
while (score[score1] != -1);
{
for (int x = 0; x < score1; x++)
{
cout << "Enter a string: ";
getline(cin,word[x]);
cin.ignore();
}
for (int x = 0; x < score1; x++)
{
cout << score[x] << "::" << word[x] << endl; // need output to be 88:: hello there.
}
}
}
什么不工作?给出错误信息,预期输出,你的程序实际上做了什么... – Lanaru 2012-07-31 19:52:20
请发布一些示例输入和输出值,以便我们可以看到发生了什么。 – 2012-07-31 20:00:10
Theres没有错误信息。例如,输入将是15,16,17 ...你好!!,你好吗?,我很好......输出应该是15 ::你好! ..等 – user1566796 2012-07-31 20:21:23