Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++
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 6-Nov-11 8:31am
Edited 6-Nov-11 8:43am
v3
Comments
Legor at 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
good
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?
  Permalink  
Comments
3boddddd at 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 at 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 at 7-Nov-11 2:39am
   
Sorry ( less time ) means less compailing time!
not time to write the code anyway LOL
Chuck O'Toole at 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 at 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 at 7-Nov-11 2:40am
   
thanks for understanding me!
Rate this: bad
good
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.
  Permalink  
Comments
3boddddd at 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 at 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 at 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 at 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
good
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.
  Permalink  
v2
Comments
3boddddd at 7-Nov-11 2:42am
   
thank you
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

i find out that is the optimal solution is:
 
ifstream myReadFile;
 myReadFile.open("text.txt");
 char output[100];
 if (myReadFile.is_open()) {
 while (!myReadFile.eof()) {
 

    myReadFile >> output;
    cout<<output;
 

 }
}
myReadFile.close();
thanks everybody
  Permalink  

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

  Print Answers RSS
0 BillWoodruff 330
1 Mathew Soji 309
2 Maciej Los 295
3 DamithSL 225
4 Afzaal Ahmad Zeeshan 217
0 OriginalGriff 6,369
1 Sergey Alexandrovich Kryukov 5,973
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 4,025


Advertise | Privacy | Mobile
Web04 | 2.8.1411019.1 | Last Updated 7 Nov 2011
Copyright © CodeProject, 1999-2014
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