[英]Reading whitespace with getline() doesn't work
#include <iostream>
#include <stdlib.h>
using namespace std;
class sheet
{
public:
void setname();
string getname();
private:
string name;
};
void sheet::setname()
{
cout << ">" ;
getline(cin,name);
return ;
}
So i have a code like this^.所以我有一个这样的代码^。 And in the main funtion i have在主要功能中,我有
sheet Personel;
Personel.setname();
But when i run my code it prints the '>' but getline doesn't work.但是当我运行我的代码时,它会打印 '>' 但 getline 不起作用。 Can anyone help me?谁能帮我?
Ah, I solved it.啊,我解决了。 It reads some leftover '\\n' previously in main.它读取了一些以前在 main 中剩余的 '\\n'。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.