# RESOLVED std::cout creates link error!

This topic is 3813 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I've been using Visual C++ 2005 for almost a year now to develop various Windows applications. I tried for the first time this week to create a simple, standard command-line program, and it generates a cryptic link error. In effort to figure it out, I deleted everything and added code line by line. std::cin.ignore(1,'\n'); works fine but somehow, std::cout<<"Test"; as well as std::cout<<"Test"<<std::endl; and all other forms of std::cout generates 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 I've looked around the internet for a few days now and can't find the solution. Why is cout a problem when cin works fine??? Thanks for the help, TLAK [Edited by - TLAK1001 on September 20, 2007 7:15:33 PM]

##### Share on other sites
Shamelessly stolen from MSDN, see if it resolves your issue.

// iostream_cerr.cpp// compile with: /EHsc// By default, cerr and clog are the same as cout#include <iostream>#include <fstream>using namespace std;void TestWide( ) {   int i = 0;   wcout << L"Enter a number: ";   wcin >> i;   wcerr << L"test for wcerr" << endl;   wclog << L"test for wclog" << endl;   }int main( ) {   int i = 0;   cout << "Enter a number: ";   cin >> i;   cerr << "test for cerr" << endl;   clog << "test for clog" << endl;   TestWide( );}

##### Share on other sites
#include <iostream> is all I've got

EDIT: I tried Nestors code, it still gives me the same error. I think there's a problem in my linker configs, but I don't really understand how alot of those config screens work.

##### Share on other sites
It actually looks like something's wrong with your VC++ install. operator<< for char is declared in one of the implementation files that are pulled in, indirectly, by iostream, so the definition should be available. Your linker configuration is probably fine; you don't need anything special to use C++ IO streams.

This is difficult to resolve remotely, because those C++ standard header implementations are actually pretty hairy. If I had access to your system, I'd open up iostream, then follow the trail of input stream files until I found a specialization of std::operator<< for char, which is the problem.

Try a Clean and Rebuild All. That's addressing symptoms, but it might have the side effect of flushing out any cached object files.

##### Share on other sites
Alright. I started combing through iostream, but I don't think I'll be able to understand any of it. I tried playing around with the << operator in other contexts, and generates some form of compile or linker error every time. I think I'll just re-install everything. I've been meaning to upgrade to Visual Studio 2008 anyway :)

Thanks guys. I'll start a new thread in a few days if a reinstall doesn't work.
TLAK

EDIT: Couldn't upgrade to 2008 (friggin Beta installers...), but a complete uninstall and reinstall (restarting the computer in between every operation) solved the problem. Hope no one else has to go through this...

[Edited by - TLAK1001 on September 20, 2007 7:24:48 PM]