当我编译secrypt.cpp程序时,我的编译器显示错误“ undefined reference to WinMain@16
”。我的代码如下
secrypt.h:
#ifndef SECRYPT_H
#define SECRYPT_H
void jRegister();
#endif
secrypt.cpp:
#include<iostream>
#include<string>
#include<fstream>
#include<cstdlib>
#include "secrypt.h"
using namespace std;
void jRegister()
{
ofstream outRegister( "useraccount.dat", ios::out );
if ( !outRegister ) {
cerr << "File could not be opened" << endl;
exit( 1 );}
string a,b,c,d;
cout<<"enter your username :";
cin>>a;
cout<<"enter your password :";
cin>>b;
outRegister<<a<<' '<<b<<endl;
cout<<"your account has been created";
}
试用版
#include<iostream>
#include "secrypt.h"
using namespace std;
int main()
{
void jRegister();
return 0;
}
这是我的错误图片:errorimage
当我编译trial.cpp程序时,它会编译并打开控制台,但没有调用该函数。这是trial.cpp程序的控制台屏幕的图像。o / p屏幕谁能帮我解决这个问题?
没有项目时,Code :: Blocks仅编译并链接当前文件。从您的图片来看,该文件为secrypt.cpp
,没有主要功能。为了编译和链接两个源文件,您需要手动进行操作或将它们添加到同一项目中。
与其他人所说的相反,使用Windows子系统main
仍然可以使用,但是没有控制台窗口。
您的其他尝试,只是编译和链接trial.cpp
,从不链接secrypt.cpp
。通常,这会导致对的未定义引用jRegister()
,但是您已在内部声明了函数,main
而不是调用了它。更改main
为:
int main()
{
jRegister();
return 0;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句