0

I have a integer number say 1234.I want to store it digit by digit in a vector. So i wrote the following

vector<int>arr;
        int c;
   while(cin>>c)
        {
            arr.push_back(c);
        }

But this is taking 1234as a whole an passing onto the vector.I don't want to use gets() and all the other functions which scan the digit as a character.So is there any way to do it?

Rohan Akut
  • 33
  • 1
  • 7
  • Learn what the modulo operation does and how to use it. – TheQAGuy Apr 21 '17 at 18:51
  • Use [`get`](http://en.cppreference.com/w/cpp/io/basic_istream/get) to peel off one character at a time. By default this will try and read a whole integer value. – tadman Apr 21 '17 at 18:53
  • Consider treating the number as a group of characters. Isolating digits is usually easier as a string of characters than a number. – Thomas Matthews Apr 21 '17 at 19:38

0 Answers0