C++ reading/output files

hater_anonimo

Honorable
May 28, 2013
2
0
10,510
Hi, i have a question about files in c++.

I need to do a program that reads a .txt file and stores it into a bidimentional character array and the show it in screen.

I have this code, but i dont know the conditional for the end of line in c++.
Basically i want to read a whole line and store it and then change the second index of the char matrix and read again, and so on, until the end of the file.

#include <iostream>
#include <fstream>
using namespace std;

int main() {
char menu_art[150][60];
ifstream fe("menu_art.txt");

for(int i=0 ; (menu_art end of line) ; i++)
{
fe.getline(menu_art[],150);
}


for(int i=0 ; i < 60 ; i++)
{
cout << menu_art[150] << endl;
}

return 0;
}
 

rgbimbochamp

Honorable
May 1, 2013
10
0
10,570
Dude, its very easy. I use a different IDE to type code. If you can just make out the solution from my code.......[read carefully]

char a[][];
for(int j=0; j<(size of the row); j++)
{ for(int k=0; k<(size of the column); k++)
{
for(int i=0; fe.eof(); i++)
{ a=fe.getline(menu_art[], size);
}}}

I quite didnt understand your approach maybe because of different style of writing. But i have done this program previously and this is pretty much what i did. btw i use Turbo c++ 9primitive but effective) . btw eof is the end of line function.
 

hater_anonimo

Honorable
May 28, 2013
2
0
10,510
Thank you for replying.
Actually i made it using a more simple way.
I used just one "for cycle" to save all the characters from the .txt file to the array.
The only problem is that if the file has more characters than spaces available in the array, it crashes, but i made it especifically for the size, so that doesn't bother me.

Here is the code:

C++:
void get_menu_art(char menu_art[60][150])
{
    int i;
    fstream fe("menu_art.txt");
    for( i=0 ; !fe.eof() ; i++)
        fe.getline(menu_art[i],150);
    fe.close();
}

But anyway, thank you for your response.