This is probably the compiler's fault, but I'm not sure...

This compiles and runs just fine:

Code:
#include <iostream.h>
#include <string>

using std::string;

int main()
{
   string hello;
   hello = "Hello World!";

   return 0;
}



This, however, gives me an error that says "error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<
char> >' (or there is no acceptable conversion)":

Code:
#include <iostream.h>
#include <string>

using std::string;

int main()
{
   string hello;
   hello = "Hello World!";
   cout<<hello;
   return 0;
}


I think the problem is that my compiler is too old. I'm using Microsoft Visual C++, but the copyright dates in the About were 1994-1998. What compiler would you guys suggest? I need one that can be downloaded for free online that is fairly easy to use, as I'm not going to be doing any uber-advanced programming anytime soon.
do you have VC++ 2005? also if you plan on any cross platformness go for the gnu compiler suite (gcc/g++)
I currently have Microsoft Visual C++ 6.0. Wikipedia tells me that it was released in 1998 and that Visual C++ 2005 is the latest release.

I want a compiler that compiles C++ code that can run on Windows XP. I'm pretty much just learning C++, so I'm not concerned about cross-platforming or anything at this point.

Another question... My programming book (Deitel's C++ How To Program, published in 2005) says that you need using::cout; before using cout by itself, but in my programming class, the book said nothing about it. Is this new(er)? Why is it necessary?
First of all change "using namespace std::string;" to just "using namespace std;" as cout is defined in the std namespace, but not the std::string namespace Razz

Also, its #include <iostream> not #include <iostream.h>

The problem lies with your code, not the compiler - make those two changes and it should work just fine
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement