Skip to main content
gamedev.net
🔒 Locked

std::string

Started by daniel_i_l 1 reply 500+ views
Original Post
daniel_i_l
daniel_i_l
I'm trying to convert an old program from arrays of chars to strings. Two questions: 1)how do i do strncmp with two strings? 2)how do i do strdup with strings, or does the std allocate the new string by itself? Thanks.
"We've all heard that a million monkeys banging on a million typewriters will eventually reproduce the entire works of Shakespeare. Now, thanks to the internet, we know this is not true." -- Professor Robert Silensky
dave_
dave_
1) a very easy way is just to use the std::string::c_str() as the parameter to strncmp. Ore just use str1.compare(str2, 0, n)


2) isnt really relevant, just use the assignment operator or the copy constructor

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.