c++ - Reading an text file into an array of strings -
I have a text file that contains many words, all are separate from the spaces I am trying to read the file And then put it in an array, so that each word is said to be a different value, which is said from the array. I am using this code, but when I run my program, it does not show anything (as it should be.)
ifstream file ("words.txt" ); If (file.is_open ()) {string wordArray [100]; For (int i = 0; i & Gt; WordArray [i]; Cout & lt; & Lt; I; } cout & lt; & Lt; "File is open."; } Nothing shows at all that I am doing this in a zero function, whatever is not currently being passed, but I do not think that doing anything with it is. The code should at least "open the file" or display any number from 1 to 100, but I do not get anything. I do not understand why this is not working, because I am including iostream, string, fstream, iomanip and sstream. If something is simple then I am unaware, please tell me.
Good, your program is probably going to be a condition in the if condition Try adding it to test your file is opening properly: if (file) {// all file input} other {std :: cerr & lt; & Lt; "Could not open file term." Txt & lt; & Lt; Std :: endl; }
Comments
Post a Comment