c++ 如何输入一组数字 以回车作为结束

利用vector或者list

比如以下,运用list

list<int> p;
int n=0;
//构造链表
int b;
while(cin>>b)
{
	p.push_back(b);
	n++;
	if (cin.get() == '\n') 
		break;
}

或者是利用 vector

int n=0;
vector<int> a;
int b;
while(cin>>b)
{
	a.push_back(b);
	n++;
	if (cin.get() == '\n') 
		break;
}

猜你喜欢

转载自blog.csdn.net/Rosalind_Xu/article/details/79678678