我一直在处理一个问题,在这个问题中,我需要分隔空间输入(< = 10),然后是两个独立数组中的下一行中的其他空间分隔输入在CPP中,我在cpp中使用了getline函数。我正面临的问题是输入输入的最后一行。我无法弄清楚我面临的是什么问题。最后一行出现时,输出停止并等待我输入一些东西后,它提供了output.Here是我的代码..输入空间在cpp中使用getline的数组中分隔的数字
while(test--)
{
int len[100];
int pos[100];
string a,b,code;
// int t=1;
cin>>code;
cin.ignore();//ignores the next cin and waits till a is not input
getline(cin,a);
// deque<char> code1;
// code1.assign(code.begin(),code.end());
int k=0;
int t=a.length();
for(int i=0;i<t/2+1;i++)//converts two n length arrays pos[] and len[]
{
scanf("%d",&len[i]);
while(a[k]==' ')
{
k++;
}
pos[i]=a[k]-48;
k++;
}
//int c;}
`
好的!你正在使用空间分隔的输入。但是在此之后你想要做什么? 意图目前还不清楚,代码看起来有点模糊。 – sjsam
看起来他可能是C++的新手。很多事情在这里都出错了。 –
@Geoff_Montee:嗯。但没有担心,因为我们在那里帮助.. – sjsam