?
Solved

Reading text into an array from a file

Posted on 2000-03-28
1
Medium Priority
?
186 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 320 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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. …
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.
Suggested Courses

850 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