Read data from an input file

Hello, i am having trouble bringing data that is located in a .txt file into my code. My instructions are to read the data into my code, using nested for-loops. I know the format looks something like this:

for( outer= 1; counter <= years; outer++ ) {

for(inner=1; 1<=12; inner++){
}// end inner

}//end outer

Im just not quite sure where to go from here. I mainly need help bringing data into the problem. Thank you
Last edited on
not gonna lie but this is pretty far from right at all. in order to be able to access data from a certain file. for instance "untitled.txt" you usually would use a while loop in order to access all of the information inside of the file.

this is probably the best place for you to start. :

http://www.cplusplus.com/doc/tutorial/files/
Thats odd, because my professor specifically said to use a for loop. The above code i posted as given right in the instructions. I would post them, but i already made a topic with my entire problem in it, but no one was able to help me.
I know that you can use a for loop in order to do this, but it's a lot more complex than using an easy while loop. I take that back. Actually I don't even know if you can use a for loop. Someone else want to answer that one?
Are you sure your inner for loop is correct?
1<=12??

If you don't have any idea how to out files into .txt file, include fstream and put your output stream inside your inner loop
Last edited on
to read or write file, u need ifstream and ofstream. Please read this http://www.cplusplus.com/doc/tutorial/files/ before you continue
i have no idea if any of what i have is correct, im just going by what my professor already gave me. Im struggling because i missed the class where he talked about nested loops. If it helps, here are my instructions:

Write a program that uses nested loops to collect data and calculate the average rainfall over a period ofyears. The program should first input the number of years. The outer for-loop will iterate once foreach year. The inner for-loop will iterate twelve times, once for each month. Each iteration of theinner loop will input the inches of rainfall for that month.


He gave the class the outer and inner loop structure above in my other post. Ive been trying to search how to complete this, but i am so lost. Please, any help is appreciated.
Topic archived. No new replies allowed.