Why is it possible to write() to STDIN?

前端 未结 3 1009
后悔当初
后悔当初 2020-12-30 14:13

I have the following code:

int main()
{
    char str[] = \"Hello\\n\";
    write(0, str, 6);   // write() to STDIN
    return 0;
}

When I c

3条回答
  •  孤独总比滥情好
    2020-12-30 14:47

    Because by default your terminal will echo stdin back out to the console. Try redirecting it to a file; it didn't actually write to stdout.

提交回复
热议问题