2016-06-08 49 views
-3

我有一個問題,讀一個大的int(1 to 10^100)爲vector問題是我不能讀取它作爲數字data-type並將其分割成矢量,所以我想要一個解決方案read的數字分別爲vector從C++中讀取int值向量

例子:

45686469 
vec[0] = 4 
vec[1] = 5 
... 
vec[7] = 9 
+1

你是怎麼嘗試當你試圖做你所描述的? – Borgleader

+0

對不起,我這裏是新手 –

回答

0

這裏是一個可能的方式做到這一點:

std::string yourinput; 
cin>>yourinput; //capture your large number as a string 

std::vector<char> vch; 

for(size_t st=0;st<yourinput.length();++st) 
{ 
vch.push_back(yourinput[st]); //move each character into the vector 
} 
+0

非常感謝你 –

+4

或更簡單:'std :: vector vch {yourinput.begin(),yourinput.end()};'。 – kfsone