Click here to Skip to main content
15,881,380 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I have a txt file looks like this:

2
123 111 132
23 34 444
3
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
Updated 6-Nov-11 7:43am
v3
Comments
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.

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?
 
Share this answer
 
Comments
Abdullatif M. Abu Al Rub 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.
Abdullatif M. Abu Al Rub 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?
Nish Nishant 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.
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.
 
Share this answer
 
Comments
Abdullatif M. Abu Al Rub 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: http://www.google.com
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.
Abdullatif M. Abu Al Rub 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: www.google.com"
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.
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.
 
Share this answer
 
v2
Comments
Abdullatif M. Abu Al Rub 7-Nov-11 2:42am    
thank you
i find out that is the optimal solution is:

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


    myReadFile >> output;
    cout<<output;


 }
}
myReadFile.close();

thanks everybody
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900