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.

Recommended Answers

All 4 Replies

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

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

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

Thx Narue...i will try the ctime function...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.