You are here:

C++/about writing and reading to disk

Advertisement


Question
Hello,

suppose i have a class Person. that prints a person's name and the number of brothers that person has got. eg

Class Person{
  public:
    getname();
    setname();
    addname();
 private:
  char *name;
  int numberOfBrothers;
 char **namesOfBrothers;
}

how do i save and also load this to a disk in cpp?

Answer
instead of using std::cin for reading and std::cout for writing formatted output, use a std::ifstream for input and a std::ofstream for output.

here are a couple of tutorials:
http://www.cplusplus.com/doc/tutorial/files.html
http://www.cprogramming.com/tutorial/lesson10.html  

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


vijayan

Expertise

my primary areas of interest are generic and template metaprogramming, STL, algorithms, design patterns and c++11. i would not answer questions about gui and web programming.

Experience

about 15 years or so

Education/Credentials
post graduate engineer

©2016 About.com. All rights reserved.