Solved

Readfile Question...

Posted on 2004-04-12
5
356 Views
Last Modified: 2010-04-01
I am trying to read a file into a string and crypt it, I don't want to use getline (since some of file does not have any specific character such as '\n'), read by char and crypt it is too slow, so I would like read amount of characters into a string, and then just crypt it.
I select 3000 character each time I read from file, my code like below...
CAN SOMEONE TEACH ME MORE EFFICIENT WAY TO DO THIS JOB???

THANK YOU SO MUCH....

//======================================================
// The code is work, but I would like to know if any efficient way to do this job... Thanks
//======================================================
const int AMOUNT = 3000;
......
ifstream ifile;
string filename = "c:\\test.txt";
ifile.open(filename.c_str());
if(!ifile.is_open())
    return;

string str = "";
char c;
while(!ifile.eof())
{
   str = "";
   for(int i = 0; i < AMOUNT && !ifile.eof(); i++)
   {
       ifile >> c;
       str += c;
   }
   doCrypt(str);
}
0
Comment
Question by:billcch
[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
  • 3
  • 2
5 Comments
 
LVL 44

Accepted Solution

by:
Karl Heinz Kremer earned 500 total points
ID: 10806439
Use ifstream::read(char *buffer, int size), so in your case this would be

char buffer[AMOUNT];
ifile.read(buffer, AMOUNT);

BTW: This is usually done with a "Points for ..." question, not a completely new question. See the EE Help for more information (http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/help.jsp#hi50).
0
 

Author Comment

by:billcch
ID: 10806463
Thank you khkremer....
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 10806556
On second thought, you should probably delete this question (have it deleted by the Support team) and reopen the first question (support can also do this for you).
0
 

Author Comment

by:billcch
ID: 10806595
hi, khkremer:
is this your email address?
eexchange@khk.net
Thanks!
billcch
0
 

Author Comment

by:billcch
ID: 10807782
Again, Thank you very much khkremer....
Billcch
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel/Word Add-in in what language? 5 144
C++ question 3 75
Path to  STL Map header file 1 81
what type of pointer is this pointer? 3 24
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
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 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…

730 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