Solved

Reading text into an array from a file

Posted on 2000-03-28
1
177 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

911 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

16 Experts available now in Live!

Get 1:1 Help Now