| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
How do I open a file and read data into an array i have a file named wordfind.in this is what my file looks like below. I am attempting to read in the information in the fist paragraph into a 2 demintional array and then compare the information in the array with the string of words to see if i can find a match in the random matrix. Here is my code and what i have writen so far can any one offer help?
cenad aatps rnrpj hello wmneo hello apple car me men ran woman #include <iostream> #include <fstream> #include <string> #include <cassert> usingnamespace std; int main() { //Greeting cout << "\nFinds a given set of words in a square table filled\n" "with single letters.As well as the direction in which the\n" "word is oriented (N, NE, E, SE, S, SW, W, NW). If a word\n" "does not occur, then the line should contain the word and\n" "then NOT FOUND.\n"; ifstream inStream; inStream.open(wordfind.in()); assert(wordfind.in.is_open()); for(; ![]() { inStream >> reading; if(reading.eof()) break; } inStream.close(); } |
|
#2
|
|||
|
|||
|
well first of all you should be opening the file with this syntax:
inStream.open("c:filename.txt"); im not sure if assert is even works but i know you could alternativly do: if(in.fail()) { cout << "Opening the file failed."; system("pause"); exit(1); } i have no idea what your doing with that for statment. if you have more questions post ill try to answer what i can. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > How do I open a file and read data into |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|