I'm just using a text file that I made as 'poop.txt'
Wrote random words and tried to open it.
I can't get the file to open..?
Is there something wrong with the code, or does it need to be saved in a certain location on the computer?
Ignore the commented out sections and prototypes!
#include<iostream>
#include<vector>
#include<fstream>
#include<string>
usingnamespace std;
void loadWords();
int sequentialSearch();
void selectionSort();
int binarySearch();
int main()
{
//"_"(?) == declares a size for a vector
//"_".size() == shows the size of the working vector
/*vector<string> words;*/
loadWords();
system("pause");
return 0;
}
void loadWords()
{
ifstream inFile("poop.txt");
string s;
inFile.open("poop.txt");
//"?".is_open returns true or false checks if file is open
while (!inFile.eof())
{
getline(inFile, s);
cout << s;
}
inFile.close();
}
void loadWords()
{
ifstream inFile("F:\\test1.txt");//file path on my laptop, edit as required;
string s;
if (inFile.is_open())
{
while(getline(inFile, s))
{
cout << s;
}
}
inFile.close();//this is redundant, the ifstream object closes automatically once it goes out of scope;
}
You'd also need to update your code as and when your input file changes, for e.g has non-whitespace delimiters, other data types etc