The string
class has a constructor that takes a NULL-terminated C-string:
char arr[ ] = "This is a test";
string str(arr);
// You can also assign directly to a string.
str = "This is another string";
// or
str = arr;
More Related Contents:
- The array index doesnt show the character [closed]
- how to change to c code while using for loop and array
- Getting a segmentation error when printing my array of strings
- isnt everything where it should be, why the segmentation fault?
- Assigning char array from ifstream breaks array if adding another char to array
- Why is conversion from string constant to ‘char*’ valid in C but invalid in C++
- std::string to char*
- .NET / C# – Convert char[] to string
- Why does streaming a char pointer to cout not print an address?
- Conversion from string literal to char* is deprecated
- Deprecated conversion from string literal to ‘char*’
- How to get the real and total length of char * (char array)?
- Return char[]/string from a function [duplicate]
- cannot convert ‘std::basic_string’ to ‘const char*’ for argument ‘1’ to ‘int system(const char*)’
- can’t modify char* – Memory access violation
- What am I not understanding about getline+strings?
- How can I create a string from a single character?
- Braces around string literal in char array declaration valid? (e.g. char s[] = {“Hello World”})
- Operator ‘==’ cannot be applied to operands of type ‘char’ and ‘string’
- C / C++ How to copy a multidimensional char array without nested loops?
- Parse string containing numbers into integer array
- C split a char array into different variables
- What is the simplest way to convert char[] to/from tchar[] in C/C++(ms)?
- Concatenate char arrays in C++
- strcmp or string::compare?
- Reverse String C++ using char array
- How can a char pointer be initialized with a string (Array of characters) but an int pointer not with an array of integer? [duplicate]
- Where are string literals stored, and can I modify them?
- Assign a string literal to a char* [duplicate]
- Assigning char array a value in C