Click here to Skip to main content
13,050,429 members (82,063 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I have a txt file looks like this:

123 111 132
23 34 444
233 33

What is the easiest way to read from a file & to get each of the values?
Compailing time is important!
-This is for a programming contest-
Please don't answer with a google search link!
Thanks every body
Posted 6-Nov-11 7:31am
Updated 6-Nov-11 7:43am
Legor 10-Nov-11 8:51am
Are you sure that the compile (not compaile!) time is of importance here. Especially for file access evaluating the runtime of your program would make much more sense.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Why do you think we would help you cheat to win a contest?
Does that sound fair to all the others who have presumably done it themselves?
3boddddd 6-Nov-11 15:09pm
first of all: i won't cheat, thats not ethical
then we are allowed to ask other people...
& finally i know how to do this but i'm asking to find out which way takes less time
thank you
Chuck O'Toole 6-Nov-11 15:16pm
The only time that you mentioned that was important was compile time, how is that a contest? Empty programs compile real quick.
3boddddd 7-Nov-11 2:39am
Sorry ( less time ) means less compailing time!
not time to write the code anyway LOL
Chuck O'Toole 6-Nov-11 16:36pm
If you're allowed to ask other people, why can't you ask Google to find out what other people are saying?
Nishant Sivakumar 6-Nov-11 16:52pm
I reckon he's already Googled and thinks that we can't give him any Google search keywords that he has not already tried.
3boddddd 7-Nov-11 2:40am
thanks for understanding me!
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Probably the fastest way to do it would be to use low level IO (open/read or fopen/fread). However, with a program this small it's unlikely that compile time will be significantly different whichever version you choose. You can find the references to the above functions quite easily; I would post a Google link but you told us not to.
3boddddd 7-Nov-11 2:41am
feel free to do any thing as long as you blive it will really help.
some peaple post anoying things like:
thats unblivable!!
thanks anyway :)
Richard MacCutchan 7-Nov-11 4:39am
Posting Google links is not unbelievable or annoying (except to lazy people); it is done when the person posting the question has shown no effort to research the problem before coming here and demanding a solution. And very often that is the only valid answer.
3boddddd 7-Nov-11 4:52am
yes i agree with you!

whatever you should know that i made researches for over a week, and i've read many refernces in c plus plus.
but a help from other coders is more optimal, what do you think?

anyway what i meant is people with a funny perspective.. when they answer with something like that:
"try this site:"
Richard MacCutchan 7-Nov-11 5:25am
As I said, in many cases that is the only answer, and in lots of cases (including yours) we do not know whether you have tried to do any research before posting your question. And, to be honest, if you could not answer this question within a week then you really need to do a lot of studying of the C/C++ language.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

You'd need to do some trial/error here. Create a few different code snippets. Then try them each with different compilers. Then pick the compiler/code combination that gives you the best compile-time. The machine itself probably won't matter since your code will be small enough that multiple CPUs won't help much. But running the compiler and the source file off an SSD or even a RAM-drive will further boost speeds.

Weird contest though, since the compiler's speed has nothing to do with your ability as a coder.
3boddddd 7-Nov-11 2:42am
thank you
Rate this: bad
Please Sign up or sign in to vote.

Solution 4

i find out that is the optimal solution is:

ifstream myReadFile;"text.txt");
 char output[100];
 if (myReadFile.is_open()) {
 while (!myReadFile.eof()) {

    myReadFile >> output;


thanks everybody

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 7 Nov 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100