Can I use line assignment and compilation?

If I have:

#include <string>

std::string myString = "Hello";

then do either:

myString = "Hello World";

or

myString+= " World";

Can I risk writing some other memory? Do I need to use string functions to add or resize a string?

+5
source share
3 answers

C std::string, which is completely excellent because it std::stringmanages its own memory.

With c-style strings using char*you need to manage your own memory.

+7
source
Line

std is like any other container class, such as a vector. They also have an adjacent memory structure, and when they need extra space, they simply redistribute the memory for themselves.

, string:: reserve(), ,

+5

Using stringit gives you the luxury of processing it, like other primitive data types, for example int float, etc.

int a = 3;It can be done without <vreda> a = 5ora += 3

Same goes for

string myString = "Hello";

myString = "Hello World";

myString+= " World";
+1
source

All Articles