Linked Questions
22 questions linked to/from char* vs std::string in c++
41 votes
7 answers
37k views
Should I use std::string or const char* for string constants? [duplicate]
I have seen code around with these two styles , I am not not sure if one is better than another (is it just a matter of style)? Do you have any recommendations of why you would choose one over ...
18 votes
5 answers
50k views
When to use std::string vs char*? [duplicate]
Possible Duplicate: C++ char* vs std::string I'm new to C++ coming from C# but I really do like C++ much better. I have an abstract class that defines two constant strings (not static). And I ...
2 votes
2 answers
922 views
Char* vs std::string [duplicate]
Possible Duplicate: C++ char* vs std::string Is there any advantage to using char*'s instead of std::string? I know char*'s are usually defined on the stack, so we know exactly how much memory we'...
258 votes
22 answers
252k views
Using arrays or std::vectors in C++, what's the performance gap?
In our C++ course they suggest not to use C++ arrays on new projects anymore. As far as I know Stroustrup himself suggests not to use arrays. But are there significant performance differences?
156 votes
7 answers
312k views
Difference between string and char[] types in C++
For C, we use char[] to represent strings. For C++, I see examples using both std::string and char arrays. #include <iostream> #include <string> using namespace std; int main () { ...
23 votes
7 answers
77k views
C++ - char* vs. string*
If I have a pointer that points to a string variable array of chars, is there a difference between typing: char *name = "name"; And, string name = "name";
9 votes
1 answer
9k views
What is the EXACT technical difference between "const char *" and "const string"
I need a deep technical explanation of what I'm about to ask, not a solution. Ive been learning pointers for a week now, I understand it pretty well. But while writing a program, I stumbled upon this ...
3 votes
3 answers
4k views
How to represent strings in a cross-platform (Windows, iOS, Android) C++ app?
I am developing an application of which the core code base would be cross-platform for Windows, iOS and Android. My question is: how should I internally represent strings used by this app to be able ...
4 votes
3 answers
3k views
std::string vs char array for static const
I want to use a string constant in multiple places in my cpp file. Should I use std::string or char[]? static const std::string kConstantString = "ConstantStringValue"; static const char ...
1 vote
4 answers
272 views
Is Returning String Reference The Best Case In Below
Let say I am designing an interface, to return the name of the child class. Note that, for different instance of a child class, their name shall remain the same. For speed and memory efficient, I ...
1 vote
5 answers
3k views
string vs char* as class member variables. Why use char* at all?
class Student { public: string name; }; vs class Student { public: char* name; }; Please correct me if I'm wrong. If we were to use char* instead of string, we will have to ...
2 votes
2 answers
592 views
Is accessing the elements of a char* or std::string faster?
I have seen char* vs std::string in c++, but am still wondering if accessing the elements of a char* is faster than std::string. If you need to know, the char*/std::string will contain less than 80 ...
-3 votes
2 answers
3k views
Difference between std::string and const char*?
What's the difference between std::string and const char*? consider following example #include <iostream> #include <string> int main() { const char* myName1{ "Alex" }; ...
0 votes
2 answers
2k views
How can I convert 0x70, 0x61, 0x73 ... etc to Pas ... etc in C++?
I am using MSVC++ 2010 Express, and I would love to know how to convert BYTE Key[] = {0x50,0x61,0x73,0x73,0x77,0x6F,0x72,0x64}; to "Password" I am having a lot of trouble doing this. :( I will use ...
1 vote
3 answers
1k views
Transform uppercase letters to lowercase and vice-versa using single parameter function (C++)
I have the trans function which uses a single parameter, has to be void, and returns through c the opposite case of a letter from a word input in main. Example: input: dOgdoG output: DoGDOg The ...