I am using the following code....
#include "stdafx.h"
#include <iostream>
int _tmain(int argc, _TCHAR* argv[])
{
std::cout << "Hello, world!\n";
return 0;
}
And I am getting the following error...
Error 1 error LNK2019: unresolved external symbol "__declspec(dllimport) class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::operator<<<char,struct std::char_traits<char> >(class std::basic_ostream<char,struct std::char_traits<char> > &,char const *)" (__imp_ $ 6DU $char_traits@D@std@@@std@@YAAAV $basic_ostream@DU $char_traits@D@std@@@0@AAV10@PBD@Z) referenced in function _wmain test4.obj
I don't know why but V C++ EE insists on having stdafx.h included otherwise I get about 25 errors. Any idea why this very basic program isn't working The annoyign thing is, I have a couple of files provided for me. A class file, class header and testing file to test the class, in the object is a call to use cout and it runs fine, but if I put it in the main funcation it won't work. Even when I basically copy the contents of the other files into the tester file.
Any ideas
Hope you can help as at the machines at uni, this program runs fine and they have visual studio 2006 and I'd like to be able to bring things home for me to work on.
Thanks in advance...
Ben.

Problems with basic Hello World program.
Azeem Sarwar
divya mittal
You can embrace all string constants with _T(). That is resolved according to _UNICODE defined or not, so that L is prepended if in unicode builds. So you have _T("Hello World!")
--
SvenC
johnvarney
You should use unicode as everything after Windows 95 has been based in Unicode. However, if you are just writing sample apps to learn, and don't want to be bothered by the L's and the w's in front of everything, you can go to project settings, then on the General page there should be a section that says "Use Multibyte" or "Use Unicode", set it to multibyte.
-Reza
KannanPV
Check to see if your program is using Multibyte or Unicode. This is usually on the front page of the project settings.
If it is set to Unicode (which it very well might be), then you need to place an L in front of the string.
std::cout << L"Hello, world!\n";
This tells it that the string is using wide characters. If your running in unicode, you generally should change the main() function to wmain() also, although that won't keep it from compiling (VC++ usually subs it at build time for you).
Also, turn off Using Precompiled Headers as they are not necessary for your project and then you can remove the #include "stdafx.h"
Let me know if that worked. Otherwise we can take a better look.
-Reza
sebastian_v_b
Did you setup this project with the VC++ project wizard Did you change any options Did you add additional lib or obj files
--
SvenC
RobDude
Change your project settings (General node in your project properties) to Multi Byte Character Set, then your code should be "compatible".
--
SvenC
kawano1h
Error 4 error LNK2019: unresolved external symbol "public: __thiscall std::ios_base::Init::~Init(void)" ( 1Init@ios_base@std@@QAE@XZ) referenced in function "void __cdecl std::`dynamic atexit destructor for '_Ios_init''(void)" ( __F_Ios_init@std@@YAXXZ) test4.obj
Hmmm.... this one looks interesting...
Warning 1 warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library test4
I changed the runtime but no luck....
Nima_DK
Gabriel3
Ok here is my code... and here is my errors...
#include "stdafx.h"
#include <iostream>
int main()
{
std::cout << "Hello, world!\n";
return 0;
}
Error 1 error LNK2019: unresolved external symbol "__declspec(dllimport) class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::operator<<<char,struct std::char_traits<char> >(class std::basic_ostream<char,struct std::char_traits<char> > &,char const *)" (__imp_ $ 6DU $char_traits@D@std@@@std@@YAAAV $basic_ostream@DU $char_traits@D@std@@@0@AAV10@PBD@Z) referenced in function _main dfgjhkl.obj
and
Error 2 fatal error LNK1120: 1 unresolved externals C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\dfgjhkl\Debug\dfgjhkl.exe 1
rjodwyer2
Because the code works well on my other compiler on my laptop. I just want to do some basic C++ programming using the VS ide as we work with VC++ at uni and I want to be able transfer my projects to and from there. It works at my uni fine jsut with standard C++, no need for all the
_T("strin") or L"strings" things.
Ben.
Rob Harris
I'm sorry for being annoying here.
Mchafu
How do I get it so I don't need to use the "L"
Oh and thanks :)
AndrewBadera
Sorry. I am very new at this.
AlexCr
Your cpp is configure to use precompiled headers. You can turn that off from project properties in the C/C++ config section under Precompiled Headers. (Menu Project->Properties, or right click your project in the solution tree view and choose Properties)
What runtime do you inlude Should be /MT or /MD which should automatically link with the default libs. Check if you have "Ignore All Default Libraries" set. Its in der Linker/Input section of your project configuration properties.
--
SvenC