I am new to C ++ and run into problems with my teacher using strings in my code. Although it is clear to me that I should stop doing this in my class, I am curious why this is wrong. In this program, the five lines that I assigned will be reused at least 4-5 times, so I put the text in the lines. I was told to stop doing this because it is inefficient. What for? In C ++, text strings should be printed as opposed to storing in strings, and if so, why? The following is part of the program, please tell me why this is bad.
string Bry = "berries"; string Veg = "vegetables"; string Flr = "flowers"; string AllStr; float Tmp1, Precip; int Tmp, FlrW, VegW, BryW, x, Selct; bool Cont = true; AllStr = Flr + ", " + Bry + ", " + "and " + Veg;
, , , .
-, , ++ - C, ++ . ( ) - C. , .
, ++. , . ; , . , , , .
, - , , . , , , , . , ; , , ++ , , , .
, :
std::string
string Bry = "berries"
std::string::operator+
+
:
std::stringstream
, - , , , , .
. , , - / , , .
. . , (, ), " " , , , ( ) .
, , , , /, . , .
- . - , :-) .. 10-
, , - const, .
- - .
. 4-5 .
, + =
+ = , +.
, = + ++ , .
, , , , , , , , .
, . , , . , , , , , .
, , AllString . , , string, . ( , - , , stl , , , , , std::string / .) , const char* #define , , r- string. , , , - , string .
string
const char*
#define
, , , - , , . - , - , . , , , - , , , .. , " ", .
string.append(); , + + =