473,394 Members | 1,701 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Conversion from std::string to char *, is there a better way?

I'm re-evaluating the way that I convert from a std::string to char *.
(Requirement: the source is a std::string, the usable contents are char *)

Here is what I've come up with:

#include <string>
#include <vector>
#include <cstring>

// presume s from somewhere, such as:
std::string s = "<initial value>";

std::vector<char> v(s.length() + 1);
std::strcpy(&v[0], s.c_str());
char * c = &v[0];
// use c, where a char * is _specifically_ required
s = c;

The above:
- doesn't use any pointers that must be manually deallocated
- is 100% portable(?)
- is 100% conformant(?)

I've seen Bjarne's similar implementation, but it uses new char * instead of
vector (obviously written before the STL was adopted).

auto_ptr<char> in place of vector<char> doesn't work because it doesn't handle
arrays.

Does anyone have comments on the above, specifically as to its suitability for
the requirements defined?
Jul 22 '05 #1
24 10986
On Thu, 10 Jun 2004 10:48:33 -0700, Julie <ju***@nospam.com> wrote:
I'm re-evaluating the way that I convert from a std::string to char *.
(Requirement: the source is a std::string, the usable contents are char *)

Here is what I've come up with:

#include <string>
#include <vector>
#include <cstring>

// presume s from somewhere, such as:
std::string s = "<initial value>";

std::vector<char> v(s.length() + 1);
std::strcpy(&v[0], s.c_str());
char * c = &v[0];
Might be a good idea to use parentheses (i.e.: &(v[0]) instead of
&v[0] here) ... I can never remember the order of the operator
precedence.
// use c, where a char * is _specifically_ required
s = c;

The above:
- doesn't use any pointers that must be manually deallocated
- is 100% portable(?)
- is 100% conformant(?)

I've seen Bjarne's similar implementation, but it uses new char * instead of
vector (obviously written before the STL was adopted).

auto_ptr<char> in place of vector<char> doesn't work because it doesn't handle
arrays.

Does anyone have comments on the above, specifically as to its suitability for
the requirements defined?


Looks OK to me.

std::string::c_str() will return a const char * pointing to the
string's character data which you can use to pass to functions which
expect constant pointers to zero-delimited C-style strings as
arguments. This is the simplest way to access the character data.

OTOH, if you have a function which expects a non-const char *, you
MUST copy the data from the constant buffer returned by c_str() to a
non-const buffer which you would generally allocate using "new
char[s.size()]", for example. It might be dangerous to cast away the
const if the function does anything but read the data (the behavior is
actually undefined by the standard).

Of course, your code would have to de-allocate the memory when done
with the buffer. I always use a smart pointer which can handle array
data (i.e. the destructor of the smart pointer calls "delete[]" and
not "delete"). The Boost library has such smart pointer templates. I
use one of my own which I adapted from code called the "grin pointer",
but the Boost library is expected to be incorporated into the next
version of the C++ standard.

The vector<char> is also a good solution, albeit one which might have
a bit more overhead (certainly not much, though) than using a simple
character array. Fortunately, the standard does guarantee that the
vector elements must be contiguous in memory, so assigning &(v[0]) to
a char * is OK.
--
Bob Hairgrove
No**********@Home.com
Jul 22 '05 #2
Julie wrote:
I'm re-evaluating the way that I convert from a std::string to char *.
(Requirement: the source is a std::string, the usable contents are char *)

Here is what I've come up with:

#include <string>
#include <vector>
#include <cstring>

// presume s from somewhere, such as:
std::string s = "<initial value>";

std::vector<char> v(s.length() + 1);
std::strcpy(&v[0], s.c_str());
char * c = &v[0];
// use c, where a char * is _specifically_ required
s = c;

The above:
- doesn't use any pointers that must be manually deallocated
- is 100% portable(?)
Looks like it
- is 100% conformant(?)
As soon as the requirement for contiguousness of 'std::vector' storage
makes it into the Standard (if it hasn't already) and trickles down to
all library implementations (if they haven't done it already to begin
with).

I've seen Bjarne's similar implementation, but it uses new char * instead of
vector (obviously written before the STL was adopted).
No, it was written before there was a suggestion that std::vector's
storage needs to be contiguous.
Does anyone have comments on the above, specifically as to its suitability for
the requirements defined?


AFAICT, the code is fine.

V
Jul 22 '05 #3
Victor Bazarov wrote:
- is 100% conformant(?)

As soon as the requirement for contiguousness of 'std::vector' storage
makes it into the Standard (if it hasn't already) and trickles down to
all library implementations (if they haven't done it already to begin
with).


Just to remove any uncertainty here, from Section 23.2.4/1 :

"The elements of a vector are stored contiguously, meaning that if v is
a vector<T, Allocator> where T is some type other than bool, then it
obeys the identity &v[n] == &v[0] + n for all 0 <= n < v.size()."
Alan
Jul 22 '05 #4
Bob Hairgrove wrote:
<snip>

OTOH, if you have a function which expects a non-const char *, you
MUST copy the data from the constant buffer returned by c_str() to a
non-const buffer which you would generally allocate using "new
char[s.size()]", for example. It might be dangerous to cast away the
const if the function does anything but read the data (the behavior is
actually undefined by the standard).


new char(s.size() + 1]
You need space for the nul char.

- Pete

<snip>
Jul 22 '05 #5
Alan Johnson wrote:
Victor Bazarov wrote:
- is 100% conformant(?)


As soon as the requirement for contiguousness of 'std::vector' storage
makes it into the Standard (if it hasn't already) and trickles down to
all library implementations (if they haven't done it already to begin
with).


Just to remove any uncertainty here, from Section 23.2.4/1 :

"The elements of a vector are stored contiguously, meaning that if v is
a vector<T, Allocator> where T is some type other than bool, then it
obeys the identity &v[n] == &v[0] + n for all 0 <= n < v.size()."


I take it, that's from the newer edition of the Standard, correct?
Is that ISO/IEC 14882-2003?

V
Jul 22 '05 #6
Julie,

If you make use of the fact that string is actually a vector, you can do the
following,
which follows somewhat your approach, but results in much simpler and few
lines of code,
and doesn't require the explicit inclusion of the vector template class.
Other than that, its exactly the same underlying idea you posted.

dave

#include <string>
#include <iostream>
using namespace std;

int foobar( char* s )
{
// do some nasty modifications to demonstrage non-const ness of s.
s[16]='d';
s[17]='o';
s[18]='g';

s[41]='f';
s[42]='o';
s[43]='x';

return 0;
}

int main( int argc, char* argv[])
{
string foo("the quick brown fox jumped over the lazy dog");
string bar(foo);
// modify the copy of the original string
char* c = &bar[0];
foobar(c);

cout << "original string is \"" << foo << "\"\n";
cout << "modified string is \"" <<bar<< "\"\n";
return 0;
}

"Julie" <ju***@nospam.com> wrote in message
news:40***************@nospam.com...
I'm re-evaluating the way that I convert from a std::string to char *.
(Requirement: the source is a std::string, the usable contents are char *)

Here is what I've come up with:

#include <string>
#include <vector>
#include <cstring>

// presume s from somewhere, such as:
std::string s = "<initial value>";

std::vector<char> v(s.length() + 1);
std::strcpy(&v[0], s.c_str());
char * c = &v[0];
// use c, where a char * is _specifically_ required
s = c;

The above:
- doesn't use any pointers that must be manually deallocated
- is 100% portable(?)
- is 100% conformant(?)

I've seen Bjarne's similar implementation, but it uses new char * instead of vector (obviously written before the STL was adopted).

auto_ptr<char> in place of vector<char> doesn't work because it doesn't handle arrays.

Does anyone have comments on the above, specifically as to its suitability for the requirements defined?

Jul 22 '05 #7
(please don't top-post. rearranged.)
Dave Townsend wrote:

"Julie" <ju***@nospam.com> wrote in message
news:40***************@nospam.com... <snip>
Julie,

If you make use of the fact that string is actually a vector, you can
do the following,
which follows somewhat your approach, but results in much simpler and
few lines of code,
and doesn't require the explicit inclusion of the vector template
class. Other than that, its exactly the same underlying idea you
posted.

dave

#include <string>
#include <iostream>
using namespace std;

int foobar( char* s )
{
// do some nasty modifications to demonstrage non-const ness of s.
s[16]='d';
s[17]='o';
s[18]='g';

s[41]='f';
s[42]='o';
s[43]='x';

return 0;
}

int main( int argc, char* argv[])
{
string foo("the quick brown fox jumped over the lazy dog");
string bar(foo);
// modify the copy of the original string
char* c = &bar[0];
foobar(c);

cout << "original string is \"" << foo << "\"\n";
cout << "modified string is \"" <<bar<< "\"\n";
return 0;
}


A string is in no way a vector<char> or any vector. It's a typedef for
std::basic_string<char>.
Furthermore, your code invokes undefined behavior, because a string's memory
is not guarenteed to be contiguous.

- Pete

Jul 22 '05 #8
Dave Townsend wrote:

Julie,

If you make use of the fact that string is actually a vector, you can do the
following,
which follows somewhat your approach, but results in much simpler and few
lines of code,
and doesn't require the explicit inclusion of the vector template class.
Other than that, its exactly the same underlying idea you posted. <snip> string foo("the quick brown fox jumped over the lazy dog");
string bar(foo);

// modify the copy of the original string
char* c = &bar[0];
foobar(c);
Two problems that I'm aware of:
char* c = &bar[0];
/May/ be valid for c, but not c+1 as it isn't required that the underlying
character elements are stored contiguously.
foobar(c);


There is no guarantee that c is '\0' terminated, the standard doesn't require
that the underlying character array(s) are null terminated.

Comments?
Jul 22 '05 #9
Victor Bazarov wrote:
Alan Johnson wrote:
Victor Bazarov wrote:
- is 100% conformant(?)


As soon as the requirement for contiguousness of 'std::vector' storage
makes it into the Standard (if it hasn't already) and trickles down to
all library implementations (if they haven't done it already to begin
with).


Just to remove any uncertainty here, from Section 23.2.4/1 :

"The elements of a vector are stored contiguously, meaning that if v
is a vector<T, Allocator> where T is some type other than bool, then
it obeys the identity &v[n] == &v[0] + n for all 0 <= n < v.size()."

I take it, that's from the newer edition of the Standard, correct?
Is that ISO/IEC 14882-2003?

V


Correct.

Alan
Jul 22 '05 #10
Dave Townsend wrote:
Julie,

If you make use of the fact that string is actually a vector, you can do the
following,
which follows somewhat your approach, but results in much simpler and few
lines of code,
and doesn't require the explicit inclusion of the vector template class.
Other than that, its exactly the same underlying idea you posted.

dave

#include <string>
#include <iostream>
using namespace std;

int foobar( char* s )
{
// do some nasty modifications to demonstrage non-const ness of s.
s[16]='d';
s[17]='o';
s[18]='g';

s[41]='f';
s[42]='o';
s[43]='x';

return 0;
}

int main( int argc, char* argv[])
{
string foo("the quick brown fox jumped over the lazy dog");
string bar(foo);
// modify the copy of the original string
char* c = &bar[0];
foobar(c);

cout << "original string is \"" << foo << "\"\n";
cout << "modified string is \"" <<bar<< "\"\n";
return 0;
}


You are making the assumption that std::string stores its string in
continguous memory, which is NOT required by the standard.

Also, the standard explicitly includes rules that allow a reference
counted implementation of strings. If you ran this code on such an
implementation, then calling foobar as you have would most likely change
*both* strings.

Alan
Jul 22 '05 #11
whoops!that was a goof, hadn't finished my morning coffee....

dave

"Dave Townsend" <da********@comcast.net> wrote in message
news:Qb********************@comcast.com...
Julie,

If you make use of the fact that string is actually a vector, you can do the following,
which follows somewhat your approach, but results in much simpler and few
lines of code,
and doesn't require the explicit inclusion of the vector template class.
Other than that, its exactly the same underlying idea you posted.

dave

#include <string>
#include <iostream>
using namespace std;

int foobar( char* s )
{
// do some nasty modifications to demonstrage non-const ness of s.
s[16]='d';
s[17]='o';
s[18]='g';

s[41]='f';
s[42]='o';
s[43]='x';

return 0;
}

int main( int argc, char* argv[])
{
string foo("the quick brown fox jumped over the lazy dog");
string bar(foo);
// modify the copy of the original string
char* c = &bar[0];
foobar(c);

cout << "original string is \"" << foo << "\"\n";
cout << "modified string is \"" <<bar<< "\"\n";
return 0;
}

"Julie" <ju***@nospam.com> wrote in message
news:40***************@nospam.com...
I'm re-evaluating the way that I convert from a std::string to char *.
(Requirement: the source is a std::string, the usable contents are char *)
Here is what I've come up with:

#include <string>
#include <vector>
#include <cstring>

// presume s from somewhere, such as:
std::string s = "<initial value>";

std::vector<char> v(s.length() + 1);
std::strcpy(&v[0], s.c_str());
char * c = &v[0];
// use c, where a char * is _specifically_ required
s = c;

The above:
- doesn't use any pointers that must be manually deallocated
- is 100% portable(?)
- is 100% conformant(?)

I've seen Bjarne's similar implementation, but it uses new char *
instead of
vector (obviously written before the STL was adopted).

auto_ptr<char> in place of vector<char> doesn't work because it doesn't handle
arrays.

Does anyone have comments on the above, specifically as to its

suitability for
the requirements defined?


Jul 22 '05 #12
"Julie" <ju***@nospam.com> wrote in message
news:40***************@nospam.com...
I'm re-evaluating the way that I convert from a std::string to char *.
(Requirement: the source is a std::string, the usable contents are char *) // presume s from somewhere, such as:
std::string s = "<initial value>";

std::vector<char> v(s.length() + 1);
std::strcpy(&v[0], s.c_str());
char * c = &v[0];
// use c, where a char * is _specifically_ required
s = c;

The above:
- doesn't use any pointers that must be manually deallocated
- is 100% portable(?)
- is 100% conformant(?)
Yes to all 3 questions.

You can also do

std::vector<char> v;
v.reserve(s.length() + 1);
std::copy(s.begin(), s.end(), std::back_inserter(v));
v.push_back(0);

The code

std::vector<char> v(s.length() + 1);

creates a vector of chars and initializes each element to 0, which may be
inefficient in some cases (though usually not noticeable).

I've seen Bjarne's similar implementation, but it uses new char * instead of vector (obviously written before the STL was adopted).

auto_ptr<char> in place of vector<char> doesn't work because it doesn't handle arrays.

Does anyone have comments on the above, specifically as to its suitability for the requirements defined?


In all implementations out there I know of, the use of

const_cast<char *>(s.c_str()) would work, and you could modify the
characters. Not a good idea though.
Jul 22 '05 #13
Julie wrote:
I'm re-evaluating the way that I convert from a std::string to char *.
(Requirement: the source is a std::string, the usable contents are char *)

Here is what I've come up with:

#include <string>
#include <vector>
#include <cstring>

// presume s from somewhere, such as:
std::string s = "<initial value>";

std::vector<char> v(s.length() + 1);
std::strcpy(&v[0], s.c_str());
char * c = &v[0];
// use c, where a char * is _specifically_ required
s = c;


how about...

#include <string>
#include <vector>
#include <iterator>
#include <algorithm>

void f()
{
// misc code here....

std::string s("some text here");
std::vector<char> v;
std::copy(s.begin(), s.end(), std::back_inserter(v));
v.push_back('\0');
// yada yada yada
}

Jul 22 '05 #14
Julie wrote:
I'm re-evaluating the way that I convert from a std::string to char *.
(Requirement: the source is a std::string, the usable contents are char *)

Here is what I've come up with:

#include <string>
#include <vector>
#include <cstring>

// presume s from somewhere, such as:
std::string s = "<initial value>";

std::vector<char> v(s.length() + 1);
std::strcpy(&v[0], s.c_str());
char * c = &v[0];
// use c, where a char * is _specifically_ required
s = c;


This worked for me, I am not sure if this is just because of my
compilers implementation....

std::string s = "A null-terminated string";

std::vector<char> v(s.size()+1, 0); // Initialize all characters to 0
const char* csptr = s.c_str(); // Get a const pointer....
std::copy(csptr, csptr + s.size(), v.begin());// Use stl copy,not strcpy
char* fromVector = &v[0]; // Still the same you did

My only concern with this code is the validity of csptr after its
declaration. Maybe someone could enlighten me on weather this is safe
or not.

Also, think about only setting to 0 the final element,
v[v.size()-1] = 0;

JLR
Jul 22 '05 #15
Jorge Rivera wrote:
Julie wrote:
I'm re-evaluating the way that I convert from a std::string to char *.
(Requirement: the source is a std::string, the usable contents are
char *)

Here is what I've come up with:

#include <string>
#include <vector>
#include <cstring>

// presume s from somewhere, such as:
std::string s = "<initial value>";

std::vector<char> v(s.length() + 1);
std::strcpy(&v[0], s.c_str());
char * c = &v[0];
// use c, where a char * is _specifically_ required
s = c;


This worked for me, I am not sure if this is just because of my
compilers implementation....

std::string s = "A null-terminated string";

std::vector<char> v(s.size()+1, 0); // Initialize all characters to 0
const char* csptr = s.c_str(); // Get a const pointer....
std::copy(csptr, csptr + s.size(), v.begin());// Use stl copy,not strcpy
char* fromVector = &v[0]; // Still the same you did


I like this better....

std::vector<char> v;
v.reserve(s.size()+1); // This should prevent resizes
v.assign(s.begin(), s.end()); // Move the contents from string to vector
v.push_back(0); // Add the NULL-termination (Shouldn't resize)

Now THIS should be both portable, compliant, and decently efficient.

JLR
Jul 22 '05 #16
On Fri, 11 Jun 2004 05:41:26 GMT, "Siemel Naran"
<Si*********@REMOVE.att.net> wrote:

[snip]
In all implementations out there I know of, the use of
const_cast<char *>(s.c_str()) would work, and you could modify the
characters. Not a good idea though.

[snip]

This is not a good idea because your program could crash! Constant
data is often stored in read-only memory sections on most operating
systems. Writing to anything in such areas of RAM would most likely
cause an access violation.
--
Bob Hairgrove
No**********@Home.com
Jul 22 '05 #17
On Thu, 10 Jun 2004 19:52:21 GMT, "Pete C." <x@x.x> wrote:
Bob Hairgrove wrote:
<snip>

You need space for the nul char.


Oops! You are quite correct.
--
Bob Hairgrove
No**********@Home.com
Jul 22 '05 #18
"Jorge Rivera" <jo*****@rochester.rr.com> wrote in message news:kUgyc.142480
std::vector<char> v;
v.reserve(s.size()+1); // This should prevent resizes
v.assign(s.begin(), s.end()); // Move the contents from string to vector
v.push_back(0); // Add the NULL-termination (Shouldn't resize)

Now THIS should be both portable, compliant, and decently efficient.


I like this, but be aware that many platforms have assembly level
optimizations of strcpy (and other functions like strchr, memcpy, memcmp,
etc) that utilize special CPU instructions. The use of v.assign or
std::copy does a byte by byte copy, and it appears most library and compiler
implementations don't provide specializations to turn the byte by byte copy
into the efficient strcpy.

So it's possible that the OP's original code is faster on some platforms.
One can only test to be 100% sure of what to do for one's particular
platform.
Jul 22 '05 #19
Julie wrote:

I'm re-evaluating the way that I convert from a std::string to char *.
(Requirement: the source is a std::string, the usable contents are char *)

Here is what I've come up with:

#include <string>
#include <vector>
#include <cstring>

// presume s from somewhere, such as:
std::string s = "<initial value>";

std::vector<char> v(s.length() + 1);
std::strcpy(&v[0], s.c_str());
char * c = &v[0];
// use c, where a char * is _specifically_ required
s = c;

The above:
- doesn't use any pointers that must be manually deallocated
- is 100% portable(?)
- is 100% conformant(?)

I've seen Bjarne's similar implementation, but it uses new char * instead of
vector (obviously written before the STL was adopted).

auto_ptr<char> in place of vector<char> doesn't work because it doesn't handle
arrays.

Does anyone have comments on the above, specifically as to its suitability for
the requirements defined?


Thanks to everyone that replied -- I got the confirmation & answers I needed.

J
Jul 22 '05 #20
Julie wrote:

I'm re-evaluating the way that I convert from a std::string to char *.
(Requirement: the source is a std::string, the usable contents are char *)

Here is what I've come up with:

#include <string>
#include <vector>
#include <cstring>

// presume s from somewhere, such as:
std::string s = "<initial value>";

std::vector<char> v(s.length() + 1);
std::strcpy(&v[0], s.c_str());
char * c = &v[0];
// use c, where a char * is _specifically_ required
s = c;


So then, under the presumption that this is about as 'clean' as it can get,
does anyone have a comment on why a method for direct access wasn't provided in
the std::string implementation? I'd have presumed that something like that
would have been requisite to be more compatible w/ C and C-style strings and
interfaces.

Something like:

class string
{
private:
char * _accessbuf; // NULL initialized in constructor
public:

char * string::access(const size_t num_chars)
{
delete [] _accessbuf;
_accessbuf = new char[num_chars+1];
copy(_accessbuf, num_chars, 0);
_accessbuf[num_chars] = '\0';
return _accessbuf;
}

void string::commit(const bool commit=true)
{
if (_accessbuf)
{
if (commit)
{
*this = _accessbuf;
}
delete [] _accessbuf;
_accessbuf = NULL;
}
}
// etc.
};

Then, accessing C-style interfaces would resolve to:

GetFileName(str.access(_MAX_PATH), _MAX_PATH);
str.commit();

instead of the cumbersome method in my original post.

Comments?

(Note: the names access and commit are completely arbitrary, more appropriate
names probably exist.)
Jul 22 '05 #21
Julie wrote:
Julie wrote:

I'm re-evaluating the way that I convert from a std::string to char *.


Maybe I misunderstood your post, by I find string::c_str() works well for
me.

--
Chris Gordon-Smith
London
Homepage: http://graffiti.virgin.net/c.gordon-smith/
Email Address: Please see my Home Page
Jul 22 '05 #22
Chris Gordon-Smith wrote:

Julie wrote:
Julie wrote:

I'm re-evaluating the way that I convert from a std::string to char *.


Maybe I misunderstood your post, by I find string::c_str() works well for
me.


c_str() returns a const pointer, so you can't directly modify the contents.

My proposal is for something that would encapsulate my original code into two
methods that would return a non-const pointer so that the contents can be
directly modified.
Jul 22 '05 #23
On Sat, 26 Jun 2004 09:25:59 -0700, Julie wrote:
Chris Gordon-Smith wrote:
Julie wrote:
Julie wrote:

I'm re-evaluating the way that I convert from a std::string to char *.


Maybe I misunderstood your post, by I find string::c_str() works well for
me.


c_str() returns a const pointer, so you can't directly modify the contents.

My proposal is for something that would encapsulate my original code into two
methods that would return a non-const pointer so that the contents can be
directly modified.


Why, exactly, do you want to do this?

--
Some say the Wired doesn't have political borders like the real world,
but there are far too many nonsense-spouting anarchists or idiots who
think that pranks are a revolution.

Jul 22 '05 #24
Owen Jacobson wrote:

On Sat, 26 Jun 2004 09:25:59 -0700, Julie wrote:
Chris Gordon-Smith wrote:
Julie wrote:
Julie wrote:
>
> I'm re-evaluating the way that I convert from a std::string to char *.

Maybe I misunderstood your post, by I find string::c_str() works well for
me.
c_str() returns a const pointer, so you can't directly modify the contents.

My proposal is for something that would encapsulate my original code into two
methods that would return a non-const pointer so that the contents can be
directly modified.


Why, exactly, do you want to do this?


From my previous post:
... to be more compatible w/ C and C-style strings and interfaces.

Jul 22 '05 #25

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Victor Hannak | last post by:
I am taking a program written in Borland C++ Builder 4 and converting the non-GUI related code to be generic c++ that can run anywhere. My main issue at this point is dealing with the string...
10
by: Angus Leeming | last post by:
Hello, Could someone explain to me why the Standard conveners chose to typedef std::string rather than derive it from std::basic_string<char, ...>? The result of course is that it is...
16
by: Khuong Dinh Pham | last post by:
I have the contents of an image of type std::string. How can I make a CxImage object with this type. The parameters to CxImage is: CxImage(byte* data, DWORD size) Thx in advance
8
by: Jason Heyes | last post by:
If s is a std::string, does &s refer to the contiguous block of characters representing s?
1
by: Wild Wind | last post by:
Hello, I have the following methods I've written to convert from String* to std::string and back: static void ConvertFromStdString(std::string& inStr, System:String* outStr) { outStr = new...
15
by: roberts.noah | last post by:
Are there any decent benchmarks of the difference between using c strings and std::string out there? Google isn't being friendly about it. Obviously this would be dependant on different...
2
by: pookiebearbottom | last post by:
Just looking for opinion on which of the 3 methods below people use in their code when they convert a 'const char *' to a 'const std::string &' came across #3 in someone's code and I had to...
11
by: Jacek Dziedzic | last post by:
Hi! I need a routine like: std::string nth_word(const std::string &s, unsigned int n) { // return n-th word from the string, n is 0-based // if 's' contains too few words, return "" //...
8
by: Edson Manoel | last post by:
I have some C++ unmanaged code that takes std::string& arguments (as reference), and fills them (possibly growing the string). I want to call this code through PInvoke (DllImport), possibly using...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.