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++?
您可以使用流操纵器http://www.cplusplus.com/reference/library/manipulators/例如:
std::cin >> std::hex >> n1 >> s >> n2;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.