Address Book C++ - Help!

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2008
Posts: 13
Reputation: Kplusplus is an unknown quantity at this point 
Solved Threads: 0
Kplusplus Kplusplus is offline Offline
Newbie Poster

Address Book C++ - Help!

 
0
  #1
Sep 18th, 2008
Okay, so im new to this website/forum. I am in programming 12, and as my final project in C++ I have decided to create an address book application. It will be "simple" and I was hoping to be able to get it to be able to:

1) Create new entry.
2) View all entries.
3) Edit an entry.
4) Delete an entry

I have very minor knowledge in I/O using files, and was hoping to get some help or a tutorial that might help.

Thanks.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,625
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 714
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Address Book C++ - Help!

 
0
  #2
Sep 18th, 2008
Start by doing the in-memory parts and then you can add serialization to file once it working the way you want. This way you can incrementally add features and also be able to prove to us that you're actually working when you ask for help on the file I/O parts. But a simple google search will give you tutorials and reference material on file I/O as well.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 13
Reputation: Kplusplus is an unknown quantity at this point 
Solved Threads: 0
Kplusplus Kplusplus is offline Offline
Newbie Poster

Re: Address Book C++ - Help!

 
0
  #3
Sep 18th, 2008
So what you're saying is;

Show us your basic source code and come back when your AT the problem?

What I know so far:

How to "CREATE" a file using i/o in files.
How to "OPEN/Read" a file.

Because what I need to know at the moment is:

How to "CREATE" a file that the user can name. ( I guess I mean an input, example:
" I would like to create a file named 'x' "))

How to "EDIT" a file.

While I probably appear to be another student with a project looking for YOU to make the program for me, I just can't seem to find a tutorial that says how to do these functions.

Thanks
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,625
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 714
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Address Book C++ - Help!

 
0
  #4
Sep 18th, 2008
>Because what I need to know at the moment is:
>How to "CREATE" a file that the user can name.
  1. std::string filename;
  2.  
  3. std::cout<<"Enter a filename: ";
  4.  
  5. if ( getline ( std::cin, filename ) ) {
  6. // Opening for writing will create the file if it doesn't exist
  7. // If the file does exist, it will be truncated
  8. // Note: The constructor requires a C-style string
  9. std::ofstream out ( filename.c_str() );
  10.  
  11. // ...
  12. }
>How to "OPEN/Read" a file.
I'm a strong believer in separate objects for reading and writing. It makes life so much easier when you're not trying to keep up with a read-write stream, so to open a file for reading you would do this:
  1. // Filename from the previous example
  2. std::ifstream in ( filename.c_str() );
  3.  
  4. // Read from the file like you would std::cin
>How to "EDIT" a file.
Editing a file ultimately ends up as "replacing" the file in practice. Unless you're appending to a file, making changes to random records in a sequential file usually means you have to make all of your changes in memory, then completely overwrite the file (okay for smaller files) or use temporary files to copy and interleave the unchanged segments and your changes, then overwrite the original file with the finished temporary.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 13
Reputation: Kplusplus is an unknown quantity at this point 
Solved Threads: 0
Kplusplus Kplusplus is offline Offline
Newbie Poster

Re: Address Book C++ - Help!

 
0
  #5
Sep 19th, 2008
Thanks a lot, that helped a ton!

What I meant by "how to edit" was this:

Is it possible to "write" text in c++ and store it in a text file and then to later recall it?

thanks again
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,625
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 714
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Address Book C++ - Help!

 
0
  #6
Sep 19th, 2008
>Is it possible
The answer is always going to be yes.

>to "write" text in c++ and store it in a text file and then to later recall it?
I'm sorry, didn't I just answer that question with my last post?
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 13
Reputation: Kplusplus is an unknown quantity at this point 
Solved Threads: 0
Kplusplus Kplusplus is offline Offline
Newbie Poster

Re: Address Book C++ - Help!

 
0
  #7
Sep 19th, 2008
> I'm sorry, didn't I just answer that question with my last post?

Im sure you did, I probably just didn't realize it.

So what I have so far is;

Ability to open/read file in c++, ability to create the file in c++.

Sorry for asking the same question over an over, but did you explain to me how to "write" inside of the text file I created? You probably did, im just blind.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,625
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 714
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Address Book C++ - Help!

 
0
  #8
Sep 19th, 2008
>did you explain to me how to "write" inside of the text file I created?
It's just like writing to cout. What more do you need to know?
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 13
Reputation: Kplusplus is an unknown quantity at this point 
Solved Threads: 0
Kplusplus Kplusplus is offline Offline
Newbie Poster

Re: Address Book C++ - Help!

 
0
  #9
Sep 19th, 2008
Okay, perhaps I phrased this wrong, what I am wanting to do is find the code that I need to enable the user (like a cin) to write in that text file.

I know how to write in the file like this,

  ofstream myfile ("filename.txt");
  if (myfile.is_open())
  {
    myfile << "This is me writing in the file.\n";
    myfile.close();
  }


But how would I alter the code so that the user can write in the file?
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,625
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 714
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Address Book C++ - Help!

 
0
  #10
Sep 19th, 2008
>But how would I alter the code so that the user can write in the file?
Combine the two concepts perhaps? You know, take input from cin, write input to file.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC