Question 3
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
#include <iostream>
#include <string>
int main() {
int pincode;
std::getline(std::cin, pincode);
std::cout << pincode << '\n';
return 0;
}
- A pincode must be long
- B std::getline reads into a std::string only; read the line into a string and convert it with std::stoi Correct
- C getline needs a delimiter
- D cin must be cin.getline
Correct Answer: Option B
Either use std::cin >> pincode, or std::string line; std::getline(std::cin, line); int pincode = std::stoi(line);.
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!