943,729 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 500
  • C++ RSS
Sep 19th, 2008
0

Need help Text File in C++

Expand Post »
Hello everyone...i need help with text file in c++,i know that we can append like ios::app and into a text file.....i need help in inserting a particular string to a particular line in a text file.....is that possible....So far i only knw tht it will append at the bottom of the text file

this is the code i did for the appending part......
ofstream enter_names("names.txt", ios::app);
ofstream enter_id("id.txt", ios::app);
cout<<"Enter Name:";
getline(cin,member_name);
cout<<"Enter Id:";
getline(cin,card_id);
enter_names<<member_name<<endl;
enter_id<<card_id<<endl;//lets say i want to store card id in line 5 of the text file.
Similar Threads
Reputation Points: 6
Solved Threads: 0
Newbie Poster
mugun is offline Offline
10 posts
since Sep 2008
Sep 19th, 2008
1

Re: Need help Text File in C++

>i need help in inserting a particular string to a particular line in a text file.....is that possible
It's possible, but not directly. You need to rewrite the file from beginning to end and insert your modified parts at the appropriate place.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Sep 24th, 2008
0

Re: Need help Text File in C++

yea....i did sumthin like,i stored em all in a vector,thn i remove wat i the user chooses,and thn delete wat the user chooses...i works....this is a library system....so i need to add the date...any std library in c++ can handle the date?....so i can plus 29/9/2008 + 5 Days will be 3/10/2008
Reputation Points: 6
Solved Threads: 0
Newbie Poster
mugun is offline Offline
10 posts
since Sep 2008
Sep 24th, 2008
1

Re: Need help Text File in C++

>any std library in c++ can handle the date?
Yes, and you would have figured that out by looking in a C++ reference. There's a header called <ctime>, and it contains the functions and types you need. Specifically, struct tm, mktime, and localtime.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Sep 24th, 2008
0

Re: Need help Text File in C++

Thx Narue...i will try the ctime function...
Reputation Points: 6
Solved Threads: 0
Newbie Poster
mugun is offline Offline
10 posts
since Sep 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Getline help
Next Thread in C++ Forum Timeline: Custom Linked Stack Problem - my pop() method does not give the underlying element?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC