輸入爲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;
}