473,466 Members | 1,351 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

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
2 1662
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: ItsMe | last post by:
Dear All, I'm getting junk email with around 140-150 kb almost everyday and it my mailbox is getting full and this emails are full of virus effected attachments. And I'm getting these emails...
10
by: ken | last post by:
hello, i'm writing a c program on a linux system. i'm debugging a segmentation fault but i don't want it to dump a core file because the memory footprint of the program is over 300Mb and i don't...
7
by: SKG | last post by:
Iam trying to read an xml file from a website and i get junk characters. But when i open the same file in browser everything is fine. here is the snippet of the code WebRequest objRequest =...
1
by: Frank Rizzo | last post by:
When I run my app in the IDE, dumping exception.ToString() information to file usually gives me a very trace on what happened including line numbers, which is really useful. When I run the app...
2
by: not aaron | last post by:
I start out with a string. Which I then encode with my own algorithm changing every characters ascii value depending on a key. I then save it to a binary file. When I generate the initial...
6
by: Rainy | last post by:
Hi, I tried searching for this and did not find this issue. I only looked at about dozen hits, I apologize if this is covered somewhere and I missed it. Without much further ado, here's the...
1
by: chebiyam | last post by:
Hi, I am using fread to read from a simple ASCII text file. fread happens fine as I give the file size that I am reading correctly. The buffer that I gave is a character string. I see some junk...
1
by: Pradeep | last post by:
Hi All, I am facing an issue where length method of std::string class gives a junk value when used in a expression. Here's an example. The code should not go into the for loop but it does...
2
by: tiijnar | last post by:
Hi Friends, I Have written a java code to send mails to some receipients.It sends to internal mail ID's in the office. An SMTP server has been provided to me. But the problem is that the mails are...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.