輸入,輸出字符串---華爲機試題

輸入爲1,2,3

即輸入數組,中間以逗號(,)爲間隔,以回車爲停止符。

cin>>c;//<span style="color:#ff6666;">遇到回車,並不讀入回車,繼續等待輸入</span>
應用c=cin.get();//取一個字符,可以取回車

#include <iostream>
using namespace std;
#define max 4
int function_4(int *t)
{
	int temp;
	char c='0';
	int n=0;
	while (c!='\n')
	{
		cin>>temp;
		t[n]=temp;
		n++;
		//cin.ignore();
		c=cin.get();//取一個字符,可以取回車
		//cin>>c;//<span style="color:#ff6666;">遇到回車,並不讀入回車,繼續等待輸入</span>
	}
	for ( int i=0;i<n;i++)
	{
		cout<<t[i]<<endl;
	}
	return 0;
}

int main()
{
      int str[max];
      function_4(str);
      return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章