cout & printf (c++)

printf("student's name/score: ");
scanf("%s/%e", &m1, &n1);

if I wrote this than I can input John/99, John will be in variable m1 and 99 will be in variable n1. How do I do this with cout and cin?
not how to put a data in a variable but how to get input of several data in a sentence and separate it into several variable.
Have you even read that link?
Extractions on cin can also be chained to request more than one datum in a single statement:
cin >> a >> b;
Last edited on
yes. oh found it. I just read the example code. Sorry... Quick question, so, using cout and cin we can only separate data using space, tab, and new line. We can't customize it as in printf?
Last edited on
You can customize it, unlike in scanf (did you run the code from your first post?)
Last edited on
You can separate the data anyway you want with cout.
cout does not provide any implicit separators. You provide what you want.
Note that printf does not provide any implicit separators either.

For delimited input, you probably want to use getline.
http://www.cplusplus.com/reference/string/string/getline/


yes I run the code. But error occur due to using std::string. After a while I decided to change it to cout and cin. Sorry, I'm completely new to this, just got my first lesson today. If it's not too bothering, can I get an example using cout and cin with / as the separator of the data? Sorry, if my English is weird, it's not my first language
Last edited on
The first form of getline in AbstractionAnon's link takes three parameter.
When text up to (and including) the '/' has been read from the stream, you can use >> to get the number.
Topic archived. No new replies allowed.