input string as number

Im dealing with very big number.

so i want to use string for my number like str = '123456...'

but how you input number but consider as string ?

GMP is not considering....
1
2
3
4
5
6
7
8
9
10
11
12

 int num;
    string input;
    
    while( true ){
        
        cin >> num; 
        if( num == 0 ) return 0;
        input.push_back(num);
        
        cout << input <<endl;
        



Last edited on
It'll be easier if u change int num to char and break on '0'


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 int num;  //probably should be a char
    string input;
    
    while( true ){
        
        cin >> num; //use 'cin' to store chars since ur using strings
        if( num == 0 ) //now need to compare for the char '0'
               return 0;   //why return ? do u mean break; ?

 //the 'int num' that goes in here is a value identifying a character on the ascii 
//table so it wont print out what u expect. again, just use char num instead...
        input.push_back(num); 
        

}//didin't see the end of the while loop
        cout << input <<endl; //this here ? to see the final result

Sleep(3000); //to keep the console open 
Last edited on
Topic archived. No new replies allowed.