std::string
has a constructor for this:
const char *s = "Hello, World!";
std::string str(s);
Note that this construct deep copies the character list at s
and s
should not be nullptr
, or else behavior is undefined.
More Related Contents:
- What it is the meaning of this error: conversion from ‘char* [40] to non-scalar type ‘std::string
- Converting std::string from const_iterator to char*?
- How to trim a std::string?
- std::string formatting like sprintf
- How to replace all occurrences of a character in string?
- Legality of COW std::string implementation in C++11
- Alternative to itoa() for converting integer to string C++? [duplicate]
- Does “&s[0]” point to contiguous characters in a std::string?
- How to concatenate a std::string and an int
- How do you construct a std::string with an embedded null?
- char* vs std::string in c++ [closed]
- How to implode a vector of strings into a string (the elegant way)
- How do you convert a C++ string to an int? [duplicate]
- Error: invalid operands of types ‘const char [35]’ and ‘const char [2]’ to binary ‘operator+’
- How do you append an int to a string in C++? [duplicate]
- How to get the number of characters in a std::string?
- Can a std::string contain embedded nulls?
- What does string::npos mean in this code?
- How do you convert CString and std::string std::wstring to each other?
- Why don’t the std::fstream classes take a std::string?
- I want to convert std::string into a const wchar_t *
- Is std::string size() a O(1) operation?
- How to trim an std::string?
- Is it possible to use std::string in a constexpr?
- Explicit copy constructor
- Legal to overwrite std::string’s null terminator?
- C++: how to get fprintf results as a std::string w/o sprintf
- Concatenating strings doesn’t work as expected [closed]
- c++ integer->std::string conversion. Simple function?
- Append int to std::string