//读取不定行数据
string str;
vector<int>vec;
while(getline(cin,str))
{
if(str.size()==0)break;
vec.push_back(stoi(str));
}
//
1
2
3
向量vec中包含1,2,3
//第一行为个数,其余行为输入
//示例1:
2
II XX
//示例2:
2
II
XX
//code(关键弄清cin)
int num;
cin>>num;
vector<string>vec(num," ");
for(int i=0;i<num;i++)
{
string str;
cin>>str;
vec[i]=str;
}
//不定行,不定列,存入二维数组
//示例
1,2,3
4,5
6,7,8
//code
#include<sstream>
vector<vector<int>>vec;
string strs;
while(getline(cin,strs))
{
if(strs.size()==0)break;
stringstream ss(strs);
string str;
vector<int>vec1
while(getline(ss,str,','));
{
if(str.size()==0)break;
vec1.push_back(stoi(str));
}
vec.push_back(vec1);
}
//读取带括号的数组
//示例
//[2,3,4,5]
//[1,4,5,7,8,9]
//code
#include<sstream>
vector<vector<int>>vec;
string strss;
while(getline(cin,strss))
{
if(strss.size()==0)break;
string strs(strss,1,strss.size()-2);
stringstream ss(strs);
string str;
vector<int>vec1
while(getline(ss,str,','));
{
if(str.size()==0)break;
vec1.push_back(stoi(str));
}
vec.push_back(vec1);
}