I just saw someone's program that assigned string this way:

string x("snow");

It seems to work, as I could display the output x as "snow". Is this a legible way to assign strings? How does it differ from

string x="snow";

?

Recommended Answers

All 2 Replies

Different generating style
1..call the generator
2..make a temp string object first,and the copy it to the left variable.

Haha, is it right?

They are roughly equivalent statements. You can do it with the standard data types too.

//both these statements are valid:
int myInt(15);     //constructor version
int myInt = 15;   //assignment version

For the standard datatypes, there really isn't any performance penalty for doing it via the assignment version. When you start to get more deeply into objects/classes then it becomes more of an issue and you're better off with the constructor version.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.