我在我的 android 设备上使用 c4droid(c++)(g++ + 仿生编译器),早期工作的代码在 2-3 小时后运行时出现错误!!
说真的,对错误一无所知,但有一个观察结果,在重新安装应用程序时,我看到问题消失了,但只是暂时的!
代码
// program with file handling search , display and modify functions
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
ofstream f("bank.dat", ios::app);
int n = 0, flag = 0;
struct bac
{
char name[10];
char amt[5];
} s;
void add()
{
cout << "\nenter the details ";
cin >> s.name >> s.amt;
f.write((char *)&s, sizeof(bac));
}
void ser()
{
ifstream fa("bank.dat");
fa.seekg(0);
char x[10];
cout << "\nenter value to be searched ";
cin >> x;
while (fa && flag == 0)
{
n++;
fa.read((char *)&s, sizeof(bac));
if (strcmp(s.name, x) == 0)
{
flag = 1;
break;
}
}
if (flag == 1)
{
cout << "\nfound";
cout << "\nAmount " << s.amt;
}
}
void mod()
{
ser();
cout<<" "<<n;
if (flag == 1)
{
f.seekp((n - 1) * sizeof(bac));
// cout<<f.tellp();
cout<<"\nnew details ";
add();
}
}
int main()
{f.seekp(0);
int ch;
cout << "\nBANK MANAGEMENT SYSTEM \n";
cout << "enter choice ";
cout << "\n1.add\n2.search\n3.delete and overwrite ";
cin >> ch;
if (ch == 1)
{
add();
}
if (ch == 2)
{
ser();
}
if (ch == 3)
{
mod();
}
return 0;
}
更新
即使这个程序给出了同样的错误
#include<iostream>
using namespace std;
int main()
{
return 0;
}
ERROR错误:'int main()' 编译的重新定义因 -Wfatal - 错误而终止 -</p>
代码逻辑上不正确,但确实用来编译!我需要知道究竟是什么导致了问题,以及代码在早期编译和运行时也是如此!