How to open a file in C++ and set its values into an array?
-
I have to write the definition for this function. However, I am having trouble setting up an array that corresponds to the contents of the file. so far I have the first part down, but I need help loading it into the array. This is what I have so far { string filename; cout<<"Enter board filename: " ; cin>>filename; ins.open (filename.c_str()); if(ins.good()) { return true; } else { while(!ins.good()) { cout<<"Error opening file"<<endl; ins.clear(); return false; } } return true; } This is what I have to have my funtion do: Asks for name of a file to read data from // Opens the file // The first number in the file (say, k) will be the number of rows // and number of columns // The rest of the file contains the data // // You may assume that the rest of the file contains k*k data items // You may also assume that k <= SIZE // // The function reads the data and enters valid data into the array // // If all goes well, sets n to k (that is, the number of rows & cols) // and returns true // // If anything goes wrong, returns false. It is okay to set n and // the elements of array a to arbitrary values in that case. // // Prompt: "Enter the name of file: " // "File didn't open" // "Wrong datatype in file"
-
Answer:
Maybe this will help: http://programmingnotes.freeweq.com/?p=1050
.#include <keperkjr> at Yahoo! Answers Visit the source
Related Q & A:
- How to open a file in external editor programmatically in eclipse plugin development?Best solution by Stack Overflow
- How to open a DAT file?Best solution by Yahoo! Answers
- How to open a bank a/c in America?Best solution by bankofamerica.com
- How to open a PPM file?Best solution by Yahoo! Answers
- How to open a .zo2 file?Best solution by solvusoft.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.