Question 8
Back to Exercise
What is the output of the following C++ program on a 64-bit system?
#include <iostream>
#include <string>
int main() {
std::string s = std::to_string(12) + std::to_string(34);
int n = std::stoi(s) + 1;
std::cout << s << ' ' << n << ' ' << std::to_string(1.5) << ' ' << std::stoi(" -7x") << '\n';
return 0;
}
- A 1234 1235 1.500000 -7 Correct
- B 46 47 1.5 -7
- C 1234 1235 1.5 -7
- D 1234 47 1.500000 7
Correct Answer: Option A
Joining "12" and "34" gives the text "1234", which stoi turns back into a number. to_string(double) prints six decimals. stoi skips leading spaces, reads the sign and digits, and stops at 'x'.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!