【发布时间】:2021-03-21 16:23:56
【问题描述】:
您好,我正在尝试在 ubunto linux 中进行文件处理。我的代码在 Windows 的虚拟工作室中运行良好,但在 Linux 中出现问题。以下是错误的代码和屏幕截图。该代码是读取文件检查文件中是否有整数,如果有则将其增加 1。 代码:
#include<iostream>
#include<stream>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
int main()
{
ifstream fin;
ofstream fout;
char abc[20];
fin.open("input.txt");
fout.open("output.txt");
while (!fin.eof())
{
fin.getline(abc, 20);
for (int j = 0; abc[j] !=0; j++)
{
char ab[20];
int s = abc[j];
int i = 0;
bool check = false;
while ((s >= 48) && (s <= 57))
{
check = true;
ab[i] = abc[j];
i++;
j++;
s = abc[j];
}
if (check)
{
ab[i] = 0;
i = 0;
int a = atoi(ab);
a++;
fout << a;
}
else
fout << abc[j];
}
fout << endl;
for (int k = 0; k < 20; k++)
{
abc[k] = 0;
}
}
fin.close();
fout.close();
}
【问题讨论】:
-
gcc->g++. -
gcc用于编译 C,g++用于 C++。
标签: c++ file file-handling