【问题标题】:Can't getline() from istringstream (C++)无法从 istringstream (C++) 获取行 ()
【发布时间】:2012-01-17 03:19:33
【问题描述】:

我有一个先前声明的char c[64];,我正在尝试查看管道输出的第一个字:

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 错误?

【问题讨论】:

    标签: c++ string iostream stringstream


    【解决方案1】:

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

    istringstream response_stream((string(c)));
    

    【讨论】:

      【解决方案2】:

      很好地展示了 C++ 的真正“力量”。

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

      【讨论】:

        猜你喜欢
        • 2018-07-13
        • 2014-11-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-07-12
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多