C++ question
I figured that someone should know this, even though its not an API-related question.
I would consider myself an intermediate C++ programmer. I'm trying to write a program that writes a list of computer parts to a .txt file. The only problem is that when i type the make of the part, well let me show you and example:
for some reason this turns out wrong on the message board.
cout<<"Processor: ";
cin>>processor;
fout<<"Processor: "<>mobo;
fout<<"Motherboard: "<>ram;
fout<<"RAM: "<<ram<<endl;
cout<<endl;
well when i type "Athlon 1Ghz" after "Processor:" is displayed, it skips "Motherboard:" and goes straight to "RAM:". the program thinks Athlon is the value of "processor" and 1ghz is the value of "mobo".
How do i fix this?
Edited by - GBates31 on 8/23/00 5:18:57 AM
-Damnit Boy, have you been eating paint chips again?-Paint chips? Oh you mean "wall candy"?
It''s because cin stops the input at space char not at ''\n'' char.
If write something after the space char, it''s take by the next cin.
If write for processor Pentium MMX 233''\n'', processor take the value pentium, mobo take MMX and RAM take 233.
Maybe the better for you, it''s take char by char for input.
If write something after the space char, it''s take by the next cin.
If write for processor Pentium MMX 233''\n'', processor take the value pentium, mobo take MMX and RAM take 233.
Maybe the better for you, it''s take char by char for input.
I suggest using cin.getline() you''ll have to check the parameters.
Epolevne
Epolevne
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement