I've been told that their are two ways too put a string in. Either through an array of chars or using #include<string> Wouldn't the string class be less memory consuming?
Pros and cons of each?
C++ Strings
Started by xXAlphaXx, Mar 04 2010 04:31 AM
4 replies to this topic
#1
Posted 04 March 2010 - 04:31 AM
|
|
|
#2
Posted 04 March 2010 - 08:17 AM
Actually, the string class will use more memory, but is also safer.
An array of chars is a fixed sized array, and requires null termination. Buffer overruns are VERY easy if you aren't careful when getting input.
The string class will use an array internally, but also stores other values. It makes buffer overruns very difficult, so you will spend much less time worrying about those issues when getting input.
An array of chars is a fixed sized array, and requires null termination. Buffer overruns are VERY easy if you aren't careful when getting input.
The string class will use an array internally, but also stores other values. It makes buffer overruns very difficult, so you will spend much less time worrying about those issues when getting input.
#3
Posted 04 March 2010 - 08:24 AM
You can do as such without using include<string>
string[90]
That will hold 89 characters.
Or you could use string library wich is easier :)
string[90]
That will hold 89 characters.
Or you could use string library wich is easier :)
#4
Posted 04 March 2010 - 01:34 PM
You could use
#include <string>
std::string mystring;
or use a char array, I kinda like the char array, but both are alright.
#include <string>
std::string mystring;
or use a char array, I kinda like the char array, but both are alright.
#5
Posted 04 March 2010 - 03:36 PM
Moudi said:
You can do as such without using include<string>
string[90]
That will hold 89 characters.
string[90]
That will hold 89 characters.
Actually it holds 90 characters.


Sign In
Create Account


Back to top









