相关疑难解决方法(0)

用C++读取管道输入

我使用以下代码:

#include <iostream>
using namespace std;

int main(int argc, char **argv) {
    string lineInput = " ";
    while(lineInput.length()>0) {
        cin >> lineInput;
        cout << lineInput;
    }
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

使用以下命令: echo "Hello" | test.exe

结果是无限循环打印"Hello".如何让它读取并打印单个"Hello"?

c++ stdin pipe cin

12
推荐指数
2
解决办法
2万
查看次数

标签 统计

c++ ×1

cin ×1

pipe ×1

stdin ×1