CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 27

Threaded View

  1. #6
    Join Date
    Aug 2006
    Location
    Timisoara, Romania
    Posts
    433

    Re: is there any problem if I set a char to '\0' within a string?

    from the example you gave (http://www.parashift.com/c++-faq-lit...html#faq-17.11)
    I don't understand why he tried to write all that code with simple char* strings.

    I would have done like this:
    Code:
    void userCode(char const* s1, char const* s2)
     {
    //concatenates strings s1 and s2 and stores it in copy (which means the function does nothing fruitful
    
       int len = strlen(s1) + strlen(s2) + 1;
       char* copy = new char[len];
       StringCchCopyA(copy, len, s1);
       StringCchCatA(copy, len, s2);
    
       delete[] copy;
     }
    and by the way, null-terminated strings (like char* copy) are faster than string and wstring. And you have all functions you need for working with them. unlike "string": or tell me how you format a string using "string".

    Also, if you work with windows API (I do), you inevitably use null-terminated strings (char*, wchar_t*), and, rather than copying them into a "string", etc. and perform operations, it is usually better (and always faster) to work with pure char* and wchar_t* functions.
    Last edited by Feoggou; October 22nd, 2010 at 11:56 AM.

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