Storing input of numbers as characters and storing them into vector

How do I get an input of very large number, store them as characters and store them into a vector?
I tried using cin.get but it only takes in one character at a time, whereas the input is of many digits.
Very confused, please help!! Much thanks!
cin.get will take many digits. cin>> will work just as well

example:
1
2
3
4
5
6
7
8
9
10
int i;
cin >> i;

int num_digits=0;
for (int decimal = 1; i/decimal != 0; decimal*=10)
    num_digits++;

vector<char> mystring;
while(num_digits--)
    mystring.push_back(num/pow((int)10,num_digits));


where we have this available:
1
2
3
4
5
6
7
8
9
int pow(int x, int y)
{
	int output=1;

	for (int i=0; i<y; i++)
		output *= x;

	return output;
}


Edit: Is it funny that I press F7 in my browser when I've finished correcting the posted code?
Last edited on
what if i have to store the input as characters instead of ints?
will this work?



cout << "Enter a non-negative number: \n";
char number = '0';
cin.get >> number;
vector<char> number;


but what if the input has many digits? do i have to initialize every digit and store it in a type char? and then transfer it to the vector?

what if i have to store the input as characters instead of ints?


Use a string.

1
2
string input;
cin >> input;
The code above DOES store it as a vector of chars:
vector<char> mystring; is a vector of chars.

First I'm inputting everything as an int, and then converting it to a char array.
Topic archived. No new replies allowed.