Reputation: 109
I want to enter a line of code that will look something like the following:
cin >> hex >> n1 >> s >> hex >> n2;
The program needs to be able to prompt the user to input a hex number followed by an expression followed by another hex number. I then follow with a series of string compares to
compare with the expression and either ad
, sub
, and etc to the two hex numbers.
I can do this with the c code like
scanf("%x %s %x", &n1, s, &n2);
How can the above statement of scanf be implemented similarly in c++?
Upvotes: 1
Views: 187
Reputation: 741
You can use stream manipulators http://www.cplusplus.com/reference/library/manipulators/ for example:
std::cin >> std::hex >> n1 >> s >> n2;
Upvotes: 1