c++ - 在 cpp 中从 argc=1 更改为 3 时输出无效
问题描述
我有一个包含 2 个案例的程序。
argc=1
= 交互模式argc=3
= 输入输出文件
if(argc == 1){
bool finish= false;
while (!finish){
try{
std::cout<<"Gcalc>";
std::string line;
std::getline(std::cin,line);
if(line==""){
finish= true;
continue;
}
和
if(argc == 3){
std::ifstream input_file(argv[1]);
std::vector<std::string> lines;
std::string line;
while (!(input_file.eof())&&std::getline(input_file, line))
{
lines.push_back(line);
}
input_file.close();
std::ofstream out(argv[2]);
/*if(!out.is_open()){
throw CouldNotOpenFile();
}*/
std::streambuf *coutbuf = std::cout.rdbuf(); //save old buf
std::cout.rdbuf(out.rdbuf());
bool finish= false;
std::cout.rdbuf(coutbuf);
out.close();
我的项目背后的所有逻辑都可以正常工作,唯一的问题是,当我std::cout
使用上面的字符串时:Gcalc
它仅在终端中有效,但是当我将其发送到我的项目的自动检查器(我是学生)时,它会识别为失败,gcam
需要在每个命令之后出现的单词没有出现。有什么建议吗?
只是为了确保 - 逻辑工作正常,cout
打印每件事情都很好,而不是gcalc
.
解决方案
推荐阅读
- ruby-on-rails - 如何使用回形针从 s3 访问同一 Ruby on Rails 应用程序中的私有和公共图像
- perl - Perl - 将 ASCII 艺术转换为使用 x 运算符
- java - 带有 Join 的 JPQL 更新语句
- ruby-on-rails - 检查 mongoid habtm 关系是否改变?
- sapui5 - SAPUI5 表格组合框:无法显示所选项目的描述
- c# - 如何正确地将“TempDataDictionary”注入我的课程?
- javascript - 如何判断输入范围元素在拖动时是增加还是减少
- python - 如何从 Python 成功保存高分辨率图像
- javascript - 如何将每个 ajax 调用中的变量传递到 1 drawchart 函数中
- laravel - Vuejs - 发布文件不起作用 - Laravel Spark