Solved

Reading text into an array from a file

Posted on 2000-03-28
1
176 Views
Last Modified: 2010-04-02
Hello!

I have a text file of approx 40,000 characters long and want to read it in character by character into an array...process it and then output it to a file. How do you read in for example 500 characters at a time...process them....then output the text to a new file. Then take the next 500 characters of the text and process that...etc.!
0
Comment
Question by:colleen_dana
1 Comment
 
LVL 22

Accepted Solution

by:
nietod earned 80 total points
ID: 2665600
fstream InFil("C:\\SOURCE.TXT",ios_base::in);
fstream OutFil("C:\\DESTINATION.TXT",ios_base::out);

const int BufSiz = 500;
char Buffer[BufSiz];

while(true)
{
   int Len = InFil.readsome(Buffer,BufSiz);
   // process the data in Buffer, not that on the last read the data will only
   // be Len long, not BufSiz long.  So always use Len as the
   // length of the data.
   OutFil.write(buffer,Len);
   if (Len != BufSiz)
      break;
}


let me know if you have any questuions.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now