简体   繁体   English

使用命令行参数打开文件时出错

[英]Error opening file using command line arguments

I am supposed to open a file using command line arguments and retrieve the data from it. 我应该使用命令行参数打开文件并从中检索数据。 I've gone through the code plenty of times and my problem is in the very beginning of everything! 我已经遍历了很多次代码,而我的问题是一切的开始!

 ifstream infile;
 infile.open(argv[1]);
 if(!(infile.is_open()))
 {
   std::cout << "Error opening file";
   return 1;
 }

The prompt I'm using to run my program is: 我用来运行程序的提示是:

 ./movie_stats < ./input/test1.in  ./my-output/test1.out

< pipes the content of ./input/test1.in to stdin <./input/test1.in的内容通过管道./input/test1.instdin

you want to call your application with the arguments like this: 您想使用以下参数调用应用程序:

 ./movie_stats ./input/test1.in  ./my-output/test1.out

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM