当我输入时,程序会自动关闭
The program autocloses when I input
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int k = 0;
int n;
int y[0];
ifstream infile;
infile.open("xxx.in.txt");
infile.seekg(1); //stores line 1 in n
infile >> n;
infile.seekg(2); //stores line 2 in array
infile >> y[0];
infile.close();
for( int x = 0; x < n; x++ )
for( int j = 1; j < n; j++ )
if ( y[x] > y[j] )
{
k = k++; //should probably use a flag
}
ofstream outfile;
outfile.open("xxx.out.txt");
outfile << k;
outfile.close();
return 0;
}
当我运行程序时,它应该自动运行,因为它不需要用户输入。但是相反,当我运行它时,它不会做任何事情,它只是一个空白的命令提示符
您正在读取和写入文件,而不是标准输入/输出。
如果要将某些内容打印到标准输出(即控制台窗口),请使用 std::cout。
相关文章:
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- 无法在windows控制台中为C++程序提供必要的输入
- 更改.cpp程序的输入文件中数据的位置会意外更改输出
- 我试图制作一个程序,要求用户输入问题和答案,但程序循环不正确
- 我的程序没有从文件中读取并输入数据
- 3-3. 编写一个程序来计算每个不同单词在其输入中出现的次数
- LLVM | codegen 用于带有命令行选项的程序输入功能
- 程序输入名称和高度并显示它。我不知道如何显示列表中最高人的姓名和身高
- 程序输入密码并解锁窗口7,8,10
- 堆栈程序输入名称并重印在C 中
- C 程序输入超过某些输入行时行不通
- C++程序 - 输入文本流
- 当程序输入主要功能时,为什么要清除此std ::向量
- 在不模拟Ctrl+V的情况下将数据粘贴到任何应用程序输入字段中.Windows c++
- c++ 将函数输出重定向到编译的程序输入,反之亦然
- 程序输入只识别单词而不识别行
- 如何与Node.js进程中的C++程序输入流进行交互
- C++命令行实用程序输入文件的位置会更改行为
- 我的程序输入无法保存到文本文件中
- 提示用户为缩写程序输入字符串