|
| Bobobob12 (3) | |||
| I'm attempting to make a a simple program, very basic, and I've come across a problem. Whenever I try to get a string value, it only gets the string up to the first space. For example: I type 'Hello World.' It writes 'Hello.' Please help.
| |||
| jsmith (3797) | |
| Use getline( cin, tex ) instead. | |
| QWERTYman (367) | |
cin only reads up to whitespace (e.g. a space or an "enter"). To read a full string, you have to type:getline(cin, tex);But, if you're using cin and getline in the same program, before the getline, you'll wanna clear the stream: cin.ignore(numeric_limits<streamsize>::max(), '\n');But you'll need to #include <limits> Hope that helps a bit. Sorry for the complexity. :D Oh, and system() is evil. Read this to see why: http://cplusplus.com/forum/articles/11153/ | |
Last edited on | |
| Bobobob12 (3) | |
| If system is evil, what do I do instead? It normally closes automaticly on me.. | |
| jloundy (161) | |
| why do you need to get so in depth on such a simple task? just use cin.get(); | |
| mcleano (733) | |
| I don't see why everyone gets worked up over using system(). I know its bad for your program - I've read Duoas article which is a very interesting read to those who haven't(QWERTYman's post). But apart from giving yourself bad habbits whilst your learning c++ whats the harm? These console programs aren't exactly at industry level and, correct me if i'm wrong because this may be down to my own ignorarnce, but the chances of you needing to write an industry level console application doesn't sound high, unless maybe its for a *nix system. I think we should be less concerned about the use of it, and more concerned with the books/tutors/etc who are teaching its use. | |
Last edited on | |
| firedraco (2607) | |
| There isn't a problem with using on random code like this, but the habit is what the problem is. Most people won't bother to learn the "right" way to do it if the evil way is easier. | |
| mcleano (733) | |
| The odd thing is though, i've never seen an example in a book or any prior online tutorial that has used system(). So where is it coming from? | |
| Duoas (3488) | |
| ' ' Apart from all the horrors and failure that comes from using system(), what's the harm? ' ' ' ' Excluding Unices, console programs aren't industry level? ' ' I sure hope this is just some sick joke... I think we ought to be more concerned about (un)teaching people dangerous and foolish habits. I cannot go and personally beat-up every bad tutor/book author/etc, nor can I personally dispose of every bad piece of information. Trying to do so is a total waste and utterly fruitless -- and would show me to be an absolute moron. A better use of my time, which I offer you freely, is to teach correct habits and principles so that you can use your own brain to do some actual, informed, intelligent computing, instead of getting stupid about stupid stuff. If that occasionally means saying, "oh by the way..." So, please, don't get so worked up about some passing advice intended to increase a programmer's worth. Seriously, anyone who has no respect for system integrity is a danger to his employer and his own self. As for me, I'm bored right now... [edit] Get distracted spraying the kids with anti-mosquito I've seen it all over the net. Even on these forums people post saying 'use system()' to do stupid things like clear the screen and pause (the two most popular offenders) ... but even to do complicated things with processes and the like when a couple simple system calls would have been easier -- and infinitely safer. | |
Last edited on | |
This topic is archived - New replies not allowed.
