Solved

Copy an array of char that can have one or more null terminators

Posted on 2013-12-09
2
321 Views
Last Modified: 2013-12-09
Is it possible to copy such an array of char to std::string?
0
Comment
Question by:tommym121
2 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 39707732
Yes, because a std::string doesnot rely on the NULL terminator, but you have to specify the length when doing so, i,e.

string s = string("1234567890\01234567890", 21); // '21' takes the '\0' terminator into account, specifying the actual size

Open in new window

0
 

Author Closing Comment

by:tommym121
ID: 39707742
Thanks.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question