473,467 Members | 2,005 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

reading and deleting from file

134 New Member
what i want to do is load a file and assign each line to a different string.

but, i cannot figure out how to do that, so, to help me do that, can you read the first line of a file, assign it to a string, and delete the line?

thanks
Sep 17 '07 #1
5 1359
sicarie
4,677 Recognized Expert Moderator Specialist
Is the file fixed in size? Do you know how many lines it will have every time? If yes, you could use a string array to hold each line, otherwise, I'd recommend either a vector (so it would be very array-like), or a linked list (if you want to do manipulations or moving the places of lines).

Once you figure that out, you can read in the whole file, and either use the API to delete and recreate an empty file, or you can try opening the file to write (and not append), which might (you'd have to try it to make sure, but I'm almost positive it would) overwrite the file (ie overwrite it with a null or some single whitespace char).

Does that make sense, or are you confused with a certain part?
Sep 17 '07 #2
lumpybanana247
134 New Member
Is the file fixed in size? Do you know how many lines it will have every time? If yes, you could use a string array to hold each line, otherwise, I'd recommend either a vector (so it would be very array-like), or a linked list (if you want to do manipulations or moving the places of lines).

Once you figure that out, you can read in the whole file, and either use the API to delete and recreate an empty file, or you can try opening the file to write (and not append), which might (you'd have to try it to make sure, but I'm almost positive it would) overwrite the file (ie overwrite it with a null or some single whitespace char).

Does that make sense, or are you confused with a certain part?
I created a function that gets the number of lines in the file and converts in to an 'int' but that will vary from about 1-1000.
if its a simple response, can you tell me how to make 'a string array hold each line'- if its hard, i could research it
thanks again
Sep 17 '07 #3
sicarie
4,677 Recognized Expert Moderator Specialist
I created a function that gets the number of lines in the file and converts in to an 'int' but that will vary from about 1-1000.
if its a simple response, can you tell me how to make 'a string array hold each line'- if its hard, i could research it
thanks again
Well, I should have clarified, its either an array of strings or an array of char *'s. Sorry about that. But once you have your array/vector/list declared, you would open the file and give it a filehandle, then I would recommend using getline() to put the line into the string. I would also recommend the file IO tutorial at cplusplus.com, it gives a pretty good explanation as well as showing useful code examples.
Sep 17 '07 #4
lumpybanana247
134 New Member
Well, I should have clarified, its either an array of strings or an array of char *'s. Sorry about that. But once you have your array/vector/list declared, you would open the file and give it a filehandle, then I would recommend using getline() to put the line into the string. I would also recommend the file IO tutorial at cplusplus.com, it gives a pretty good explanation as well as showing useful code examples.
thank you very mmuch sicarie
Sep 18 '07 #5
sicarie
4,677 Recognized Expert Moderator Specialist
thank you very mmuch sicarie
No problem, post again if you get stuck!
Sep 18 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: GMK | last post by:
Dear all in my asp.net application i have a text file that is installed with my application on the server. this text file is filled with data through a web interface in my application. i need to...
3
by: Luis Esteban Valencia Muñoz | last post by:
Hi everyone, I created a VB.NET application that looks at a folder in my local system from which I can read the file, enter data into the database and delete the file. I am using the filewatcher...
6
by: belmontpress | last post by:
I wish to delete some files from a directory after reading them but have the problem that the system says that the files are in use and cannot delete them even though I have set the StreamReader to...
2
by: fool | last post by:
Dear group, I am a beginner in php and I was little bit experience in C language. I want to read a file's content and delete the first line of the file and display those lines which has got...
1
by: vadarv | last post by:
Hia! I'm a total amateur to VBS but need help on a VBS script. This is used in a HMI system from Siemens called WinCC, used for process viewing and control. What I need to is to write to a table...
9
by: peter.bremer | last post by:
Hi all, I've got a SQL Server database that contains zipped information stored in (binary) image fields. To complicate things, this zipped data is combined with plain-text data. I've verified...
3
by: Kimera.Kimera | last post by:
I'm trying to write a program in VB.net 2003 that basically deletes all files, folders, sub-folders and sub-sub folders (etc). The program is simply for deleting the Windows/Temp folder contents,...
5
by: aboxylica | last post by:
I have a file which contains something like this >ref|NC_001133| CCACACCACACCCACACACCCACACACCACACCACACACCACACCACACCCACACACACA CATCCTAACACTACCCTAACACAGCCCTAATCTAACCCTGGCCAACCTGTCTCTCAACTT...
15
by: arnuld | last post by:
This is the partial-program i wrote, as usual, i ran into problems halfway: /* C++ Primer - 4/e * * Exercise 8.9 * STATEMENT: * write a function to open a file for input and then read...
4
by: Miner Jeff | last post by:
Hello, I have a basic question about reading files. I have several data files where the filenames are identical except for a short (3 character) prefix. I inherited this code and the person who...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.