(c++)现在有这样一些字符串,如何用cin把他们放在一个二维的string数组里边呢?

start: integer; // begins here
stop: integer; // ends here
s: string;
c: char; // temp
//以下为字符串

我的代码如下(我用的getline)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<sstream>
using namespace std;
const int MAXN= 1000+100;
string table[MAXN][200];
const int MAX= 1000+100;
int main()
{
string line;
int n=0,a[MAXN],i;
string table[MAXN][200];
while(getline(cin,line)) //读入单词
{
stringstream ss(line);
i=0;
while(ss>>table[n][i]) i++;
cout<<table[n][i];
a[n]=i;//统计每行有多少个单词
n++;//统计行数
}
for(i=0; i<n; i++)
{
cout<<a[i]<<endl;
for(int j=0; j<a[i]; j++)
{
cout<<table[i][j]<<" ";
}
cout<<endl;
}
return 0;
}

MAXN和 MAX的值设置小一点试试,比如:
const int MAXN= 10; //1000+100;
另外,读入单词的循环条件加一项line!=""要好些(直接打回车表示输入结束):
while(getline(cin,line) && line!="") //读入单词
温馨提示:答案为网友推荐,仅供参考