Trying something basic and need help

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: Trying something basic and need help

Post by MarauderIIC »

getch() isn't portable either, I don't think.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
LeonBlade
Chaos Rift Demigod
Chaos Rift Demigod
Posts: 1314
Joined: Thu Jan 22, 2009 12:22 am
Current Project: Trying to make my first engine in C++ using OGL
Favorite Gaming Platforms: PS3
Programming Language of Choice: C++
Location: Blossvale, NY

Re: Trying something basic and need help

Post by LeonBlade »

Yeah it is... wait... lol... oops...
Alright just cin a line lol

char temp;
cin >> temp;
There's no place like ~/
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: Trying something basic and need help

Post by Falco Girgis »

^

Not a good idea, the enter/newline is going to remain in the input buffer.
User avatar
LeonBlade
Chaos Rift Demigod
Chaos Rift Demigod
Posts: 1314
Joined: Thu Jan 22, 2009 12:22 am
Current Project: Trying to make my first engine in C++ using OGL
Favorite Gaming Platforms: PS3
Programming Language of Choice: C++
Location: Blossvale, NY

Re: Trying something basic and need help

Post by LeonBlade »

Then we all give up...
Lets make a new forum about lawn chairs...

</sarcasm>

Then what do we use...?
There's no place like ~/
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: Trying something basic and need help

Post by Falco Girgis »

Code: Select all

char temp[2];
cin >> temp;
;)
User avatar
LeonBlade
Chaos Rift Demigod
Chaos Rift Demigod
Posts: 1314
Joined: Thu Jan 22, 2009 12:22 am
Current Project: Trying to make my first engine in C++ using OGL
Favorite Gaming Platforms: PS3
Programming Language of Choice: C++
Location: Blossvale, NY

Re: Trying something basic and need help

Post by LeonBlade »

Amazing... So what IS in conio lol
There's no place like ~/
User avatar
Aeolus
Chaos Rift Regular
Chaos Rift Regular
Posts: 179
Joined: Fri Jan 16, 2009 2:28 am

Re: Trying something basic and need help

Post by Aeolus »

lol wow you guys confuse me. Saying all this technical shit. I looked in the chapter i read and theirs nothing about holding the program open to see the result.

Im thinking about just doing something like

Code: Select all

char f;
cin >> f;
Hyde from That 70's Show wrote:Woman are like muffins... Once you have a muffin you will do anything to have another muffin... And they know that.
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: Trying something basic and need help

Post by Ginto8 »

you could also simply do cin.clear() before cin.get(). Or you could use getchar(), which is in iostream.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Trying something basic and need help

Post by dandymcgee »

Just add:

Code: Select all

while( 1 ){}
Program will stay open as long as you need :)

NOTE: I just realized this actually "works".. For those of you that don't know this is a joke, it's a joke. DO NOT use this method.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: Trying something basic and need help

Post by MarauderIIC »

Aeolus, use

char temp[2]; cin >> temp;

to hold it open. As opposed to

char temp; cin >> temp;
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
LeonBlade
Chaos Rift Demigod
Chaos Rift Demigod
Posts: 1314
Joined: Thu Jan 22, 2009 12:22 am
Current Project: Trying to make my first engine in C++ using OGL
Favorite Gaming Platforms: PS3
Programming Language of Choice: C++
Location: Blossvale, NY

Re: Trying something basic and need help

Post by LeonBlade »

Why array?
There's no place like ~/
User avatar
Aeolus
Chaos Rift Regular
Chaos Rift Regular
Posts: 179
Joined: Fri Jan 16, 2009 2:28 am

Re: Trying something basic and need help

Post by Aeolus »

Thanks again Marauder
Hyde from That 70's Show wrote:Woman are like muffins... Once you have a muffin you will do anything to have another muffin... And they know that.
User avatar
eatcomics
ES Beta Backer
ES Beta Backer
Posts: 2528
Joined: Sat Mar 08, 2008 7:52 pm
Location: Illinois

Re: Trying something basic and need help

Post by eatcomics »

LeonBlade wrote:Why array?
I was wondering the same thing lol...
I have been using system("PAUSE");
and I have been meaning to change it but I'm too lazy to find a solution.... So an explanation would be nice lol
Image
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: Trying something basic and need help

Post by MarauderIIC »

Why array? Because Falco said in an earlier post that otherwise the newline would be stuck on the buffer *shrug*
Last I heard newlines on windows from user were just \n, so, I dunno.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: Trying something basic and need help

Post by Ginto8 »

Instead of using an array, you could do this:

Code: Select all

cin.clear(); // clear the input buffer
cin.get() // wait for <break> to be pressed
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
Post Reply