|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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. thanks for any |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
* rob:
> 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. You're using the Dev C++ integrated development environment (IDE). Probably that means you're using the g++ compiler. But other compilers can be used with the same IDE. > 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. Try running your program from a command interpreter. For more with that consult a group dedicated to your operating system. Cheers, & hth., - Alf -- A: Because it messes up the order in which people normally read text. Q: Why is it such a bad thing? A: Top-posting. Q: What is the most annoying thing on usenet and in e-mail? |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On Oct 17, 5:41 pm, rob <rob1...@gmail.com> wrote:
> 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. > > thanks for any // there is no need to be including arguments u don't need. // i just compiled this in .NET and it works fine //when u running the code make sure u not in debug mode so it dosen't blow by. #include <iostream> #include <string> using namespace std; int main() { string name; cout <<"Enter your name _\b"; cin >> name; cout <<endl; cout << name<< endl; return 0; } |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On Oct 18, 12:41 am, rob <rob1...@gmail.com> wrote:
> 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. > > thanks for any Something related to implementation, There was sth related to conio header and pause() function, try them and see what happens, your code looks fine at first sight. cin.get() just extracts the newline in the stream, and you are not using that for anything why did you put that there? HTH, Regards |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
"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. |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
On Wed, 17 Oct 2007 22:41:31 -0000 in comp.lang.c++, rob
<rob1101@gmail.com> wrote, >having problem with is taking user input, putting it into a string Look to the std::getline() function before anything else for that. |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
forgive my lack of knowledge but i didn't understand most of what
anyone said. 1) im not sure how to run it in a command interpreter but i will look into it. 2) i used #include <stdlib.h> because it was in the book, the book hasn't really explained what any of this does in detail yet. Im --- pretty sure im not in debug mode, i just use compile and run to execute the program. 3) i used cin.get() at the end, so the program won't just quit when its done and waits so i can actually see the output. is that ok? or is ---there a better way of doing this? 4) im not sure what you mean by that. but i took cin.get() out all together and the program still acts the same way. 5) I have read up a bit about it on the internet but none of what i read has really ed. could someone please point me in the right --- direction? |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
"rob" wrote:
> forgive my lack of knowledge but i didn't understand most of what > anyone said. Did you try what I proposed? It *did* work for me on DevC. If the word "macro" has no meaning to you, here is a chance to try to figure out what it means. Wikipedia is often ful in explaining geek-speak. |
|
![]() |
| Outils de la discussion | |
|
|