How to convert a char array to a string

0 votes
Converting a C++ string to a char array is as simple as using the string's c str function and then strcpy.

But how do you do the opposite?I have a char array like this: char arr[] = "This is a test"; which will be transformed to string str = "This is a test."
Jul 14 in C++ by Nicholas
• 4,720 points
20 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In C++

0 votes
1 answer

How to convert string to char array in C++?

Simplest way I can think of doing ...READ MORE

answered Jun 20 in C++ by Damon
• 4,760 points
37 views
0 votes
1 answer

How can I convert a std::string to int?

There are some new convert methods in C++ that convert std::string to a numeric type. As an alternative to str.c str() atoi(str.c str()) atoi(str.c str() you can make use of std::stoi std::stoi ...READ MORE

answered Jun 1 in C++ by Damon
• 4,760 points
38 views
0 votes
0 answers

C++ convert from 1 char to string?

I simply need to cast one character to string.  The inverse method is as easy as str[0]. The following suggestions did not work for me: char c = 34; string(1,c); //this doesn't work, the ...READ MORE

Jun 29 in C++ by Damon
• 4,760 points
20 views
0 votes
0 answers

How to create a dynamic array of integers

How can I use the new keyword ...READ MORE

Jul 15 in C++ by Nicholas
• 4,720 points
20 views
0 votes
0 answers

How to initialize an std::string with a length?

How can I correctly initialise a string if its length is specified at build time? #include <string> int length = 3; string word[length]; //invalid ...READ MORE

Jul 27 in C++ by Nicholas
• 4,720 points
5 views
0 votes
1 answer

How to convert an instance of std::string to lower case

#include <algorithm> #include <cctype> #include <string> std::string data = "Abc"; std::transform(data.begin(), ...READ MORE

answered 6 days ago in C++ by Damon
• 4,760 points
7 views
0 votes
2 answers

How an object array can be converted to string array in java?

System.arraycopy is the most efficient way, but ...READ MORE

answered Aug 8, 2018 in Java by Sushmita
• 6,900 points
2,960 views
0 votes
1 answer

Why is char[] preferred over a string?

Strings are immutable. That means once you've ...READ MORE

answered Jun 14, 2018 in Java by scarlett
• 1,290 points
239 views
0 votes
4 answers

How to convert a char to a String?

There are two ways you can do ...READ MORE

answered Dec 29, 2020 in Java by Roshni
• 10,500 points
193 views
0 votes
1 answer

Easiest way to convert int to string in C++

The C++11 version has introduced the std::stoi ...READ MORE

answered Feb 10 in Others by Rahul
• 9,000 points
38 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP