Hello, i am new to c++ so i hope you guys can help me out. I have searched the answer up on google and while i find examples i cant quite understand whats going on yet. I want to make a simple file read function so i dont have to keep reading a file in 100 different places in my program.
Here is what i have, it is very simple and obviously wrong. It is supposed to read the file and store it in a array (which it does) and then return the array so i can use the data.
Code:string ReadWrite(char * FileName) { int i = 1; // String to hold all the file lines in string line[50]; string FileContent; ifstream myfile (FileName); if (myfile.is_open()) { while ( myfile.good() ) { // Read a line out of the file getline (myfile,line[i]); // Increase the Array by one so we dont overwrite ++i; } myfile.close(); } else cout << "Unable to open file"; return line[]; }
Any help is greatly appreciated. Sorry for messy formatting.




Reply With Quote