#include<filestream> problems reading file

#include <iostream>
#include <iomanip>
#include <cassert>
#include <fstream>
#include <string>


using namespace std;

int main ()

{
ifstream inFile; //input file stream variable
string fileName;
ofstream outFile; //output file stream variable
char y;
char n;
double rate1;
double rate2;
double average;
double name;


cout << "Welcome to Adam's survey program" << endl;
cout << endl;
cout << "Please enter the name of your data file: ";
cin >> fileName;
inFile.open(fileName.c_str()); //open the input file

if (!inFile)

{

cout << "Cannot open the input file. "
<< "The program terminates. " << endl;
return 1;
}
/*My program will not recognize my fileName variable name and output error value of 1.The program needs to know the exact location of the txt. file correct? Including the entire pathname?
PLEASE HELP!*/
Last edited on
Use std::getline() to get information into std::strings:

http://www.cplusplus.com/reference/string/getline/
Topic archived. No new replies allowed.