|
-
Sep 4th, 2007, 06:28 AM
#1
Thread Starter
PowerPoster
[RESOLVED] Linking error
I want a code that open a text file and able to write few text on it. Here is the code I have written.
Code:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ofstream file;
file.open ("example.txt");
if(file.is_open())
{
file << "Write a text line";
file.close();
}
else
{
file << "Unable to wirte text";
}
return 0;
}
When I compiled it, gives the following error.
Compiling...
rbf.cpp
Linking...
LIBCD.lib(wincrt0.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function _WinMainCRTStartup
Debug/ReadFile.exe : fatal error LNK1120: 1 unresolved externals
What's wrong there. Can you guys help me.
“victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha
-
Sep 4th, 2007, 08:01 AM
#2
Re: Linking error
It appears you've created a Win32 application, and haven't specified the correct entrypoint.
An entrypoint, is where your code begins its main execution (hence, the function name "main"). Basic console applications, use this:
Code:
int main()
{
return 0;
}
Win32 applications however, need to pass some information into the entrypoint, like this:
Code:
int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)
{
}
Make sure you take note of what the tutorials say.
chem
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Sep 4th, 2007, 10:29 PM
#3
Thread Starter
PowerPoster
Re: Linking error
If I replace my code with your given, is it ok.
By the way, I refer the following tutorial to test this.
http://www.cplusplus.com/doc/tutorial/files.html
“victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha
-
Sep 5th, 2007, 02:51 AM
#4
Re: Linking error
That tutorial assumes you're writing a console application, or, at the very least, an application that can run with the entrypoint "main".
Make sure, before you put any code anywhere, that you have created a Console Application. At the moment, you have created a Windows Application, and tried to put 'console code' inside it.
chem
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Sep 5th, 2007, 03:09 AM
#5
Thread Starter
PowerPoster
“victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|