#include <iostream>
#include <vector>
#include <string>
#include <string.h>
using namespace std;
int main()
{
int temp1;
vector<int> v1;
//输入不定长数组方法一
cout << "输入不定长数组方法一:" << endl;
do
{
cin >> temp1;
v1.push_back(temp1);
} while (getchar() != '\n');
for (auto a1 : v1)
{
cout << a1 << " ";
}
cout << endl;
//输入不定长数组方法二
cout << "输入不定长数组方法二:" << endl;
int temp2;
vector<int> v2;
while (cin >> temp2)
{
v2.push_back(temp2);
if (cin.get() == '\n')
{
break;
}
}
for (auto a2 : v2)
{
cout << a2 << " ";
}
cout << endl;
//输入不定长数组方法三
cout << "输入不定长数组方法三:" << endl;
int temp3;
vector<int> v3;
int x;
while (cin >> temp3)
{
v3.push_back(temp3);
x = cin.get();
if (x == '\n')
{
break;
}
}
for (auto a3 : v3)
{
cout << a3 << " ";
}
cout << endl;
//输入不定长字符串
cout << "输入不定长字符串:" << endl;
string s;
while (1)
{
cin >> s;
if (cin.get() == '\n')
{
break;
}
}
cout << s << endl;
system("pause");
return 0;
}
输入不定长数组
最新推荐文章于 2023-11-25 18:48:24 发布