N
noobles
I'm trying to make a command line parser, but I'm not exactly sure
where to put my file.txt file so that this thing can read it. The most
logical place seemed to be the directory the project was in, but that
didn't work.
#include <fstream>
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
int main(){
ifstream file;
string fileName ="file.txt";
file.open(fileName.c_str());
if (!file){
cout << "Failed to open file" << endl;
return -1;
}
string newLine;
while(std::getline(file, newLine)) {
cout<<newLine<<endl;
}
return 1;
}
where to put my file.txt file so that this thing can read it. The most
logical place seemed to be the directory the project was in, but that
didn't work.
#include <fstream>
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
int main(){
ifstream file;
string fileName ="file.txt";
file.open(fileName.c_str());
if (!file){
cout << "Failed to open file" << endl;
return -1;
}
string newLine;
while(std::getline(file, newLine)) {
cout<<newLine<<endl;
}
return 1;
}