By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,510 Members | 1,821 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,510 IT Pros & Developers. It's quick & easy.

junk information an the end of dumping out string to a file.

P: n/a
I have a class which has an attribute 'path' of type 'string'.

class MyClass {
public:
MyClass(const string& parentpath, int count) ;
void dump(ostream& os) const;

private:
string path;
int type;
}
MyClass::MyClass(const string& parentpath, int count) {
type = // a function to find out type;
ostringstream apath;

apath << parentpath;
apath << "/";
apath << count;

path = apath.str();
}

void MyClass::dump(ostream& os) const {

os << " type:" << type;
os << " path:" << path;
os << endl;

}

In some case, not always , I this print out junk at the end of 'path',

type:3 path:/-/3/3/3/0/0^@^@^@^@1^@^@^@^@#b^Hh^LU^^AA

Can you please tell me what did I do wrong?

Thank you.

Apr 19 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
yi*****@gmail.com wrote:
I have a class which has an attribute 'path' of type 'string'.

class MyClass {
public:
MyClass(const string& parentpath, int count) ;
void dump(ostream& os) const;

private:
string path;
int type;
}
MyClass::MyClass(const string& parentpath, int count) {
type = // a function to find out type;
ostringstream apath;

apath << parentpath;
apath << "/";
apath << count;

path = apath.str();
}

void MyClass::dump(ostream& os) const {

os << " type:" << type;
os << " path:" << path;
os << endl;

}

In some case, not always , I this print out junk at the end of 'path',

type:3 path:/-/3/3/3/0/0^@^@^@^@1^@^@^@^@#b^Hh^LU^^AA

Can you please tell me what did I do wrong?

You didn't post real code. Post real code, then we can talk.

V
--
Please remove capital As from my address when replying by mail
Apr 20 '06 #2

P: n/a
yi*****@gmail.com wrote:
I have a class which has an attribute 'path' of type 'string'.

class MyClass {
public:
MyClass(const string& parentpath, int count) ;
void dump(ostream& os) const;

private:
string path;
int type;
}
Please qualify string and ostream with std::
Missing semicolon.


MyClass::MyClass(const string& parentpath, int count) {
type = // a function to find out type;
What's that you want to find with type?
ostringstream apath;

apath << parentpath;
apath << "/";
apath << count;

path = apath.str();
}

void MyClass::dump(ostream& os) const {

os << " type:" << type;
os << " path:" << path;
os << endl;

}

In some case, not always , I this print out junk at the end of 'path',

type:3 path:/-/3/3/3/0/0^@^@^@^@1^@^@^@^@#b^Hh^LU^^AA

Can you please tell me what did I do wrong?
Well, are you sure it is the part that you posted that has contains the
error?

To really help us help yourself perhaps you should post a complete
program that demonstrates the problem. It is hard to guess in what
context is your class used and under that condition does the error pop up.

But before doing so, you may like to run your debugger, check what's
passed in MyClass constructor in the first place.

Thank you.


Regards,
Ben
Apr 20 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.