cin.ignore();

i want to take rest of string from input buffer to b after using cin.ignore();
whats wrong in that?
eg: say first i entered the string "hello how are you";
at first i take first character in c then after ignoring space rest part in b ?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>

using namespace std;

int main()
{
   char c,*b;
   cout<<"enter any string"<<endl;
   c=cin.get();
   cin.ignore(225,' ');
   cin>>b;
   cout<<b<<endl;

    return 0;
}
How do you expect reading into a char * to even work? Use std::string.
Last edited on
whats wrong in that b is pointer to character string
according to me that should store string "how are you"
It can not work. cin will not magically allocate space for you. It completely violates RAII. And no, it would only contain "how", and "are you" would still be left in cin.
okay got it! thanks
Topic archived. No new replies allowed.