CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 21 of 21
  1. #16
    Join Date
    Apr 1999
    Posts
    27,449
    Originally posted by Guysl
    Thanks.
    I'm using the same headers but keep getting:
    error C2679: binary '<<' : no operator defined....

    I have the DX9 SDK installed too, with default project setting
    uses its libs, could it be the reason? any idea?

    Regards,
    Guysl
    I get no errors compiling the simple code with the proper headers. Maybe you've trashed (overwritten) your STL version with an older one where iostreams doesn't overload the std::string type, or your directory paths are pointing to this older version.

    That's basically the problem with VC++'s "iostream.h" -- it knows nothing about std::string, so there was no operator << written for the VC++'s version "iostream.h".

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; April 26th, 2004 at 01:16 PM.

  2. #17
    Join Date
    Aug 2002
    Location
    Madrid
    Posts
    4,588
    There must be a problem on your system. It compiles fine in my VC6 too. It's in the standard as well (21.2.2).
    Get this small utility to do basic syntax highlighting in vBulletin forums (like Codeguru) easily.
    Supports C++ and VB out of the box, but can be configured for other languages.

  3. #18
    Join Date
    Jun 2003
    Location
    Gjøvik, Norway
    Posts
    204

    Re: Thank everyone

    Originally posted by taguato
    ...
    char result[10];
    string Str("Hello Gurus, good day!");
    int n = 10;

    strcpy(result,Str.substr( Str.size() - n , n).c_str());
    ...
    Is there any perticular reason you are using a char[10] and not a std::string?
    Code:
    std::string Result;
    std::string Str("Hello Gurus, good day!");
    int n = 10;
    
    Result = Str.substr(Str.size() - n , n);

  4. #19
    Join Date
    Mar 2004
    Location
    Israel
    Posts
    638
    Paul and Yves, thanks.
    I've reinstalled VC++ , now strings output works fine.

    Regards,
    Guy
    **** **** **** **** **/**

  5. #20
    Join Date
    Apr 2004
    Location
    Asuncion, Paraguay
    Posts
    17

    good question

    Why using char[10] and not std::string? well, it´s called inexperience.

    I could not get my program to accept any of that sintax. I take it was because I did not include the right headers. The code snipped coming from jlou (I think) might shead some light: I am using <string.h>. I will try the one below.

    Thanks again.

    Luis

    PS: btw: while we are at it, what do I have to include to use the CString class?

    #include <iostream>
    #include <string>
    int main()
    {
    std::string myString = "Hello World!";
    std::cout << myString << std::endl;
    }

  6. #21
    Join Date
    Apr 2004
    Location
    Asuncion, Paraguay
    Posts
    17

    A humbling experience...

    Hi gurus:

    The code snipped, along with the "std::string Mystring" worked like a charm... amazing. Just for you guys to get a good laugh, this is what I have to do to get those darn 10 bytes off the string:

    // -----------------------------------------------------------------------------------------
    // RightS: Copies the rightmost NumChars characters from the string_in to string_out
    // -----------------------------------------------------------------------------------------
    void RightS(char*string_in,int NumChars, char*string_out)
    {
    char temp[80];

    int length = strlen(string_in);
    int i, start, ctr;

    start = length - NumChars;

    for (i = 0; i <= NumChars; i = i + 1)
    {
    ctr = start + i;
    temp[i] = string_in[ctr];
    }

    temp[NumChars+1] = '\0';

    strcpy(string_out,temp);
    }

    You can laugh, no problem. I know it´s bizarre, but.. you know, desperation is the mother of creativity, I guess.

    But that little code snipped took it of it elegantly. And yes, it was <string>. the <string.h> it´s for something else... I write off as a good experience.

    Thanks again,

    Luis

Page 2 of 2 FirstFirst 12

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