while (true)
{
scanf("%s", &namepart);
strcat(name, naampart);
if (scanf("") != 0) break;
}
It''s easy to read just one string from input, but I can''t get it working when the loop is involved.
I don''t care if it uses ''cin'' or ''scanf''...
Could you guys help me out?
Thanks!
Multiple input with cin or scanf
Hey,
I''m working on a C++ DOS-app (console).
Now, I''m trying to read multiple values from the input stream and terminate as soon as there''s no longer input but it just keeps asking for yet another word.
I can say something like ''enter your name and end the line with a separated point'' like e.g.
John Jones .
but that''s just not user-friendly.
Here''s my code:
******************************StrategicAllianceOn the day we create intelligence and consciousness, mankind becomes God.On the day we create intelligence and consciousness, mankind becomes obsolete...******************************
Why not just use:
This will retrieve the full line into name. You could also use cin.getline() but that requires a char* which is silly in my opinion (probably has to do with exception safety).
Is this what you were looking for?
Dire Wolf
www.digitalfiends.com
Edited by - Dire.Wolf on January 7, 2001 4:19:32 AM
<string>
<iostream>
int main()
{
using namespace std;
cout << "Enter name: ";
string name;
getline(cin, name);
return 0;
}
This will retrieve the full line into name. You could also use cin.getline() but that requires a char* which is silly in my opinion (probably has to do with exception safety).
Is this what you were looking for?
Dire Wolf
www.digitalfiends.com
Edited by - Dire.Wolf on January 7, 2001 4:19:32 AM
[email=direwolf@digitalfiends.com]Dire Wolf[/email]
www.digitalfiends.com
www.digitalfiends.com
Thanks,
I encountered a small problem with the getline function trying to read standard input while I actually hadn''t given the name in yet, but I figured it out.
Thanks for the help!
Stefan.
I encountered a small problem with the getline function trying to read standard input while I actually hadn''t given the name in yet, but I figured it out.
Thanks for the help!
Stefan.
******************************StrategicAllianceOn the day we create intelligence and consciousness, mankind becomes God.On the day we create intelligence and consciousness, mankind becomes obsolete...******************************
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement