c-str Questions

7

Solved

I understand c_str converts a string, that may or may not be null-terminated, to a null-terminated string. Is this true? Can you give some examples?
Dwaindwaine asked 14/9, 2011 at 12:37

6

I have read several places that the difference between c_str() and data() (in STL and other implementations) is that c_str() is always null terminated while data() is not. As far as I have seen in ...
Shinar asked 11/10, 2008 at 20:59

4

Solved

After C++11, I thought of c_str() and data() equivalently. C++17 introduces an overload for the latter, that returns a non-constant pointer (reference, which I am not sure if it's updated complete...
Verbalism asked 27/11, 2018 at 13:3

7

Solved

In one of my programs, I have to interface with some legacy code that works with const char*. Lets say I have a structure which looks like: struct Foo { const char* server; const char* name; }; ...
Irresolution asked 23/6, 2011 at 15:12

3

Solved

In the C++ reference of c_str() in std::string the following appears: Return value Pointer to the underlying character storage. data()[i] == operator[](i) for every i in [0, size()) (until C++...
Lazos asked 20/8, 2017 at 12:40

3

Solved

I've read various descriptions of std::string::c_str including questions raised on SO over the years/decades, I like this description for its clarity: Returns a pointer to an array that contai...
Denominative asked 5/1, 2017 at 13:0

1

I'm playing around with a new init system with #![no_std] and extern crate rlibc and making syscalls with asm, and currently trying to not allocate memory either. So the scope of possible tools I h...
Secret asked 26/7, 2014 at 8:27

3

Solved

Why would I ever want to call std::string::data() over std::string::c_str()? Surely there is some method to the standard's madness here...
Worcestershire asked 7/10, 2009 at 21:43

4

Solved

This is from a small library that I found online: const char* GetHandStateBrief(const PostFlopState* state) { static std::ostringstream out; // ... rest of the function ... return out.str().c...
Hydroxy asked 17/4, 2010 at 4:3
1

© 2022 - 2024 — McMap. All rights reserved.