Using string type in class for file storage
Hey fellas, question:
Is is legal to store a class to file when one or more of it's members are of the string type?
I tried doing this and I get a fatal runtime error, in which the string.cc file is brought up and one of the lines highlighted:
Code:
string::traits_type::char_out(os, s[x]);
The full code for the block (with the problem line highlighted) is as follows:
Code:
ostream& RWSTDExport operator<< (ostream & os, const string& s)
{
typename string::size_type x;
if ((os.flags() & ios::adjustfield) == ios::right)
for (x = 0; x < os.width() - s.length(); x++)
string::traits_type::char_out(os, os.fill());
for (x = 0; x < s.length() ; x++)
string::traits_type::char_out(os, s[x]);
if ((os.flags() & ios::adjustfield) == ios::left)
for (x = s.length(); x < os.width(); x++)
string::traits_type::char_out(os, os.fill());
return os;
}
Remember, all the code I have shown you above is from the string.cc header file. (#include <string>).
If anyone has even the foggiest idea of what this means, I'd appreciate your help.
Just when I thought I found something great
Drat, double drat, it never ends.
This is just great.
I'm becoming more and more disappointed with C++.
Here I was hoping, just HOPING that this string datatype would save me some code. It's so easy to use.
But it seems that its not radically different than char*. In fact, it seems like nothing more than char* with the strcmp, strcpy etc. etc. all overloaded into the +,-,=,* etc operators and made a little more like Visual Basic.
I'm steadily loosing respect for C++. Aside from its extensions of C, I can't swear to it's uniqueness as a language unto itself. I guess C++ is like the Broodwar addon to StarCraft.
Anyways, thanks for clearing things up for me man. I really appreciate it.
I have since changed out all of my string variables to char*. There's no point to me using string anywhere in my program. It works just fine now.