473,382 Members | 1,376 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

How can I write a class with "string or char*" member variable to a file...?

Hi to every body...:D
I'm a novice C++ programmer & I've a question,
How can I write a class as follow to a file...

Class A
{
public:
// Accessors Methods...
Sep 29 '07 #1
2 1644
On 2007-09-29 23:29, ba********@yahoo.com wrote:
Hi to every body...:D
I'm a novice C++ programmer & I've a question,
How can I write a class as follow to a file...

Class A
{
public:
// Accessors Methods...
.
.
.
private:
int itsAge;
string itsName;
// char itsName[ 80 ];
};

I know that, I should use ofstream &....
but there is a problem:
"itsName" is a "string or char*" & It can not be written in desired
file...
Actually it is a char array, and nothing else.
Should I write a self writting method for this class to write itself
to a file or what?

Decide on a file-format for writing you class, then implement

std::ostream& operator(std::ostream& o, const A& a);

so that it writes the members of A in the correct format. For more
information search for serialisation, also take a look in the FAQ:
http://www.parashift.com/c++-faq-lite/

--
Erik Wikström
Sep 29 '07 #2
Hi,
Thanks alot...
I got the Clue...
It's good to have such a community...

Sep 30 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: verb13 | last post by:
In an asp page in localhost I have this: Set x = Server.CreateObject("Scripting.Dictionary") And I get this error: Invalid class string If I omit Server like this: Set x =...
3
by: Paul | last post by:
Help, please, I can't get any addins working on a new machine. I registered the correct plugin names into the right registry location. I gave VSControlHostLib with a strong name, created the...
9
by: Fei Liu | last post by:
In Accellerated C++, the author recommends that in a header file one should not declare using std::string, using std::vector etc instead one should directly specify the namespace specifier in...
5
by: chris_doran | last post by:
/COMMENT has been removed from the linker that comes with VS2005, and use in source code of: #pragma comment(exestr, "this is a string") gives the message: warning LNK4224: /COMMENT is no...
10
by: lovecreatesbea... | last post by:
Is it correct and safe to compare a string object with "", a pair of quotation marks quoted empty string?If the string object: s = ""; does s contain a single '\'? Is it better to use...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.