c**********e 发帖数: 2007 | 1 #include
#include
#include
#include
using namespace std;
int main()
{
std::string line1(3, '*'), line2(5, '*');
std::cin >> line1;
std::getline(std::cin, line2);
std::cout << "Line 1:" << line1 << std::endl;
std::cout << "Line 2:" << line2 << std::endl;
std::cout << "EOF\n";
return 1;
}
Given the program above, what happens if, when the program is run, the user
enters "Hello world!" followed by a newline?
a) It will print out:
Line 1: Hello
Line 2: world!
EOF | r****t 发帖数: 10904 | | j***i 发帖数: 1278 | 3 为什么,我也选b了
【在 r****t 的大作中提到】![](/moin_static193/solenoid/img/up.png) : b 错了, 是 e
| r****t 发帖数: 10904 | 4 (2nd function version:)
istream& getline ( istream& is, string& str );
Get line from stream
...
The delimiter character is delim for the first function version, and '\n' (
newline character) for the second. The extraction also stops if the end of
file is reached in is or if some other error occurs during the input
operation.
所以 getline 就从 hello 后面那个空格开始读到 \n 了。
【在 j***i 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 为什么,我也选b了
|
|