2011-12-09 40 views
3

我已经事先声明char c[64];,我想看看管道输出的第一个字:无法从istringstream(C++)函数getline()

read(pipe_replacement_to_main[READ_END], c, BUF_SIZE); 
istringstream response_stream(string(c)); 
string response_string; 
getline(response_stream, response_string, ' '); 

和gcc给我在第四行:

error: no matching function for call to ‘getline(std::istringstream (&)(std::string), std::string&, char)’ 

我什至不知道它是如何试图调用函数。我声明istringstream是否错误?

回答

5

Most vexing parse,在构造函数response_stream的内部添加一对括号。

istringstream response_stream((string(c))); 
2

很好的证明了C++的真正“功率”。

您声明response_stream变量的方式实际上是一个函数,而不是类型istringstream