2017-09-04 95 views
0

here中摘录了示例。std :: cin.getline不等待输入

相关代码:

char line[chat_message::max_body_length + 1]; 

    while (std::cin.getline(line, chat_message::max_body_length + 1)) 
    { 
     chat_message msg; 
     msg.body_length(std::strlen(line)); 
     std::memcpy(msg.body(), line, msg.body_length()); 
     msg.encode_header(); 
     c.write(msg); 
    } 

    c.close(); 
    t.join(); 

的应用立即退出,而无需等待我把聊天消息中 我再没修改代码预期使用Windows,而不是一个控制台应用程序(我还在。附加控制台Alloc & AttachConsole)

回答

0

长话短说,你的std::cin istream无效。 std::cin.getline返回对std::istream的引用,其代表std::cin。回滚继承hiearchy,std::basic_ios,其中std::cin派生自,具有operator bool过载,如果您的流上的badbiterrorbit已设置,则该过载将返回false。

我打赌你的控制台,因为没有以传统方式设置,没有正确地连接到std::cin