another c++ question 4 replies

Please wait...

The_Computer_Wizard

The Force is strong with him

50 XP

10th September 2006

0 Uploads

321 Posts

0 Threads

#1 14 years ago

ok, im trying to get back into c++ and im trying to get all the components down to a program i want to write for school, ive remembered how to do several but i was never taught this one and my friend doenst remember so maybe someone on here can help ok what i want to do is cin a string with a/several space(s) my friend gave me a header called apstring this is what i have, and apstring can handel spaces (as you will see in the code im about to post) it just wont work when i try and cin it this is my code #include #include "apstring.h" #include "apstring.cpp" int main() { apstring C1, C2; C2="Goodbye World"; cout<> C1; cout<< C1; // will only cout the first word of whatever i type system ("PAUSE"); return 0; } im using dev-C++ 4, any suggestions?




Macaquinhos

O rly?

50 XP

11th May 2006

0 Uploads

235 Posts

0 Threads

#2 14 years ago

you might have to use the getline() command instead of cin

ok, now i'm sure of it, you need to use the getline() command.

Cin stops reading up to the first space, getline() reads white spaces as characters.




Revenge Advanced Member

Shizzle my nizzle

117,165 XP

28th July 2004

0 Uploads

10,354 Posts

0 Threads

#3 14 years ago

Yep, that new header file doesn't replace cin, it adds a new command which complements it.




kotfquig

Master skinner-in my mind :-P

50 XP

2nd August 2004

0 Uploads

284 Posts

0 Threads

#4 14 years ago

ok, i can use the getline() to do an echo program (i can have it spit back out whatever i type in) but i cant get it to infile anything with getline()




The_Computer_Wizard

The Force is strong with him

50 XP

10th September 2006

0 Uploads

321 Posts

0 Threads

#5 14 years ago

ok, i know this is an OLD thread now, but through the help of my friend i FINALLY figured out why it wasnt workingi was looking at my infile program and was like "i know this logic is correct" and it was, apparently there was/is a problem with dev, idk if its just mine but if i executed through the compiler it wouldnt work, if i directly went to the exe file it wouldso the reason im posting this is incase someone else was having trouble with this, cause i was getting frustrated because i knew my logic wasnt wrong on it