CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2007
    Location
    Bangalore India
    Posts
    262

    Building std::string obj from char*

    Hello Guys,

    Is it nessessary that to build string object one has to provide NULL terminated char array or just char array without NULL termination will also do..

    Thanks in Advance

    Regards
    Prashant,
    Dont forget to rate my post if you find it useful.

  2. #2
    Join Date
    May 2007
    Location
    Bangalore India
    Posts
    262

    Re: Building std::string obj from char*

    Please Ignore it..Got the answer..
    Dont forget to rate my post if you find it useful.

  3. #3
    Join Date
    Apr 2004
    Location
    England, Europe
    Posts
    2,492

    Re: Building std::string obj from char*

    For those who find this thread ...


    You can do either:

    Code:
    const char x[4] = {'a', 'b', 'c', 0};
    const char y[3] = {'a', 'b', 'c'};
    
    std::string a(&x[0]);
    std::string b(&y[0], 3);
    My hobby projects:
    www.rclsoftware.org.uk

  4. #4
    Join Date
    Feb 2005
    Location
    "The Capital"
    Posts
    5,306

    Re: Building std::string obj from char*

    If you happen to invoke the char* argument taking constructor of std::string, then yes, it is necessary to have it null-terminated.

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