I have a char
, a plain old character, that I would like to turn into an std::string
. std::string(char)
doesn't exist of course. I could create an char array and copy it in, I could go through string streams, or many other little roundabout routes. Currently, I prefer boost::lexical_cast
, but even that seems too verbose for this simple task. So what's the preferred way?
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- how to split a list into a given number of sub-lis
- thread_local variables initialization
相关文章
- JSP String formatting Truncate
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
just use the overload that takes a char?
i.e.
string(1, 'A')
std::string
has a constructor that takes a number and a character. The character will repeat for the given number of times. Thus, you should use:This works on gcc C++ 4.9.2 (http://ideone.com/f3qhTe)
You still can use the string constructor taking two iterators:
Update:
Good question James and GMan. Just searched freely downloadable "The New C Standard" by Derek M. Jones for "pointer past" and my first hit was: