[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Reading text into an array from a file

Posted on 2000-03-28
1
Medium Priority
?
185 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
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

656 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