Monday, May 24, 2010

Very simple C++ help?

I'm using visual Studio .net 2003. It's a completely legal version so I know it wasn't tampered with.





This is my code:





@include %26lt;iostream.h%26gt;





int main()


{


cout %26lt;%26lt; "Hello World!\n";


return 0;


}











This is the result:





Linking...


HelloWorld.obj : error LNK2019: unresolved external symbol "long __stdcall About(struct HWND__ *,unsigned int,unsigned int,long)" (?About@@YGJPAUHWND__@@IIJ@Z) referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z)


Debug/HelloWorld.exe : fatal error LNK1120: 1 unresolved externals








My tutorial book says to type it just like that, and I started it as a blank C++ file.. is my compiler broken or am I missing something fundamental?





Thanks





-Simba

Very simple C++ help?
Linker tells you, that the code in your function "WndProc" tries to call function "About", but you do not have any function with that name. Looks like you created your project as "Windows Application" (while it should be "Console application") and didn't manage to remove all the unneeded generated code.





The easiest way to solve your problem is to start all over:


* Select from the main menu: File-%26gt;New-%26gt;Project


* In "New project" dialog select "Visual C++" to the left and "Win32 Project" to the right. Name your project and press "Ok".


* In "Win32 Application Wizard" window select "Application Settings", then set application type as "Console application". Now press "Finish" - the project will be created.


* Now type your code and compile. Good luck!
Reply:wheres stdio.h?





ignore the scope resolution operator guy, he works for Turbo...








Did you select the right t kind of Project?


try creating a simple pre-made console app from the templates...
Reply:Problem is with the @include


should read #include %26lt;iostream.h%26gt;





stdio.h is referenced in iostream.h but as a general rule include it anyway
Reply:When the linker gives you errors, it means that it cannot find the .lib files that it needs to link your program.


However, in this case, it looks like you might have told VS to build a Windows32 program, instead of a console program. I don't have VS, but I have Visual C++ 2005 Express and the project setup should be similar. When you create a project, specify a 'Win32 Console Program.'


Also, I think you're not supposed to put the '.h' file extension after the name of the header file that you wish to #include in Microsoft Visual C++. (Look in the compiler's help file for 'Standard C++ Library Overview.'


Remember to insert this line after your '#include' lines:


using namespace std;
Reply:is it


@include %26lt;iostream.h%26gt; ?





it should be


#include %26lt;iostream.h%26gt;





use "#" instead of "@"





and also you should


#include %26lt;stdio.h%26gt;


but in some compilers, it is default included.
Reply:// test.cpp : Defines the entry point for the console application.


//





#include "stdafx.h"


#include "io.h"








int _tmain(int argc, _TCHAR* argv[])


{


printf("Hello World");


return 0;


}








That is my code on VS 2005. I used a console application template.





The link file iostream.h does not exist in my system. That's strange. Sorry, if I can't be of much help.
Reply:Use std::cout


1 comment: