CMD:程序.exe 1< "A:/input.txt"产生无输出
CMD: program.exe 1< "A:/input.txt" yield no output
我已经更新了这个问题:
int main(int argc, char *argv[]){
cout << "cout argc: " << argc << endl;
cerr << "cerr argc: " << argc << endl;
cout << "cout usatty: " << _isatty(_fileno(stdin)) << endl;
cerr << "cerr usatty: " << _isatty(_fileno(stdin)) << endl;
if (argc == 1 && _isatty(_fileno(stdin)))
{
cout << "cout Error: No space between num and <" << endl;
cerr << "cerr Error: No space between num and <" << endl;
}
}
Cmd 输出:
program.exe 0< "A:/input.txt"
cout argc: 1
cerr argc: 1
cout usatty: 0
cerr usatty: 0
program.exe 1< "A:/input.txt"
cerr argc: 1
cerr usatty: 64
cerr Error: No space between num and <
program.exe 2< "A:/input.txt"
cout argc: 1
cout usatty: 64
cout Error: No space between num and <
现在我可以检测到 <1 和 <2(但不能区分它们(,<0 仍然未被发现。
所以对我来说还有两个问题:
1( 如何打印同时适用于 <1 和 <2 的错误消息
2( 如何检测 <0
C++程序打开了三个标准文件:编号0
处的标准输入、编号1
处的标准输出和编号2
处的标准错误(C++也有带std::clog
的标准日志,但它与标准输出相同,只是它没有缓冲(。
你对1<
所做的是尝试将输入重定向到标准输出。这当然是行不通的。
当你在1
和<
之间有一个空格时,就像在1 <
中一样,然后你把1
作为参数传递给程序(程序将被放置在argv[1]
中,索引与参数无关(,重定向到标准输入。
相关文章:
- 如何将 txt 文件中的行分隔为组件C++
- 在CMakeLists.txt的安装功能中使用.cmake文件有什么用
- 一种在C++中读取TXT配置文件的简单方法
- 如何修复此iFile以将.txt输出到控制台
- 无法打开.txt文件
- CMakeLists.txt中的命名空间表示法
- Arduino从Txt读取整数
- 如何使用CLion在Mac上创建一个新的.txt文件
- "input.length();"的目的是什么?
- 如何拆分文件中.txt字母并使用c ++使用数组进行扑克?
- 使用fstream对txt文件中的数字进行循环
- Visual Studio在尝试读取resource.txt文件时崩溃
- 更正 CMakeList.txt 用于谷歌测试的文件?
- 如何从txt文件中读取多个不同长度的数组?
- 在一次迭代中从 txt 文件中读取多行
- 将生成文件转换为 CMakeLists.txt等效项
- 使用循环将多行写入.txt
- CMD:程序.exe 1< "A:/input.txt"产生无输出
- 编写一个C++ pgm 以从文件"input.txt"读取,每当遇到句点时插入换行符并将修改的内容写入"output.txt"
- C++ Input to .txt