Dominic van Berkel posted:
Can anybody help me? I'm desperately trying even to *create* strings,
but it simply won't work. I don't want to use c-strings, and i've
tried about every possible header file. What am i doing wrong?
Dominic
Well first of all, here's a C++ program:
int main()
{
}
If that doesn't compile, the burn your "compiler".
Firstly, there's a variable type in C++ called "char". This type is used
to store a character. For instance:
char blah = 't';
When you write a character in C++, you surround it with apostrophes.
Anyway, a string is a load of characters. What we do is stick a load of
"char"'s side by side in memory (in an array), like so:
char hello[6] = { 'H', 'e', 'l', 'l', 'o', 0 };
That zero at the end signals the end of the string. Without it, they CPU
would got reading through memory until it reaches a dead end.
Anyway, you say you don't want to use "C strings", which is what I have
described above.
I presume you're on about the class called "std::string".
#include <string>
int main()
{
std::string blah("Hello!");
blah = "Monkey!";
blah += " and Ape!";
}
-JKop