CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2006
    Location
    Dallas, TX
    Posts
    47

    unable to output string?

    Code:
    	void write_on_paper(string words)
    	{
    		if (InkLevelPercent <=0)
    		{
    			cout << "Oops! Out of ink!" << endl;
    		}
    		else
    		{
    			cout << words << endl;
    			InkLevelPercent = InkLevelPercent - words.length();
    		}
    	}
    1>c:\users\noah\documents\visual studio 2008\projects\objsnclasses\objsnclasses\pen.h(40) : error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)
    The error code is referring to
    cout << words << endl;
    I'm still learning C++ and this is an example from the book. But it won't compile. can anybody help please? thanks in advance.

  2. #2
    Join Date
    Aug 2006
    Location
    Dallas, TX
    Posts
    47

    Re: unable to output string?

    Nevermind i found my issue my compiler doesn't include string in the std namespace. i needed to include <string>

  3. #3
    Join Date
    Apr 1999
    Posts
    27,449

    Re: unable to output string?

    What header files did you include?

    Those functions and classes are declared in their appropriate #include files, so that code is not complete unless you post what files are included.

    Regards,

    Paul McKenzie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured