#include <iostream>
using namespace std;
int main()
{
char user_name[50];
cout << "what is your name?" << endl;
cin.getline (user_name, 50, '\n');
cout << "hello, " << user_name << ", how are you today?" << endl;
}
我需要第二个cout所有在一行,但它的阅读回车键甚至我放了一个delim。我怎样才能解决这个问题?C++ getline ..我不能避免读取ENTER键
hello, johnny walker
, how are you today?
我更正了语法(在编辑中)。您的代码在我的电脑上运行,并提供所需的输出。 – Sharad 2012-02-14 00:38:29
此外,此图形可能有所帮助:http://meta.stackexchange.com/a/65088/136659 – Jacob 2012-02-14 00:45:09
“getline”的文档说“如果找到分隔符,它将被提取并丢弃,即它不存储,并且接下来的输入操作将在它后面开始。“ – 2012-02-14 00:51:32