0

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.

2
Contributors
4
Replies
5
Views
9 Years
Discussion Span
Last Post by mugun
0

>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.

0

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

0

>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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.