Question about assigning/copying strings

C++ Community,

Real quick BASIC question==> With the arrival of the various latest editions of C++ (such as C++11 and C++14 etc.)....

Is it VALID and acceptable (an also good style and form) to assign ONE STRING to ANOTHER string in the following manner==>

string1 = string2; //assign strings?

Or is this illegal and the way to do it is just use the assign method for the string==> string1.assign(string2);

Thoughts?

Xanadu
It's legal, clear and conventional. If I saw people routinely using assign to copy a string where they could just use = , I would wonder why.
Excellent Repeater! Excellent!

So this is really a "style" question then? The "=" operator doesn't loose any functionality or is going to allow me to start getting into some slippery situations - whereas assign would be more strict and make sure things didn't go wrong? For instance I'm not going to get into allocation memory issues or over-run?

I should also mention that I am only 'grabbing' integers in the form of strings and then converting them to actual integers for use...... so I am not trying to capture a whole chapter from "War and Peace".

Thanks for your insight on this!

Xanadu
Off the top of my head, I cannot think of any situation in which I could not copy a string using =, but could with assign. string is a proper object that looks after its own internals and size and so on. assign can do a few more fancy things with other parameter inputs, but for copying a string, just use =
Thank you Repeater. I appreciate your insight and will consider this question solved.

Xanadu
Topic archived. No new replies allowed.