Afficher un message
Vieux 18/10/2007, 02h36   #5
osmium
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: newbie needs with user input into strings

"rob" writes:

> hello all. im a newbie in C++ and programing in general. what i am
> having problem with is taking user input, putting it into a string and
> then displaying that string again. i am using the dev C++ compiler.
> here is the code
>
> #include <iostream>
> #include <stdlib.h>
> #include <string>
>
> using namespace std;
>
> int main(int argc, char *argv[])
> {
>
> string name;
>
> cout << "Enter name: ";
> cin >> name;
> cout << endl << "Your name is " << name << endl;
>
> cin.get();
>
> return 0;
> }
>
> it will let me input what ever i want but nothing happens when i hit
> enter, the window just stays blank until i hit enter again then the
> window closes.


Sometimes one cin.get() is not enough in DevC, your program needs two of
them To avoid such problems, I use this macro

#define STOP while(1) std::cin.get();

and then call it to freeze the display. It also looks neater, there are
other occasions where you will have to use the STOP macro as well.


  Réponse avec citation
 
Page generated in 0,06384 seconds with 9 queries