I am trying to open a file that the user specifies and then read from that file. Here is my code. I cannot seem to get fstream to work with the cin file name.
Any help will be much appreciated.
Thanks!
#include <iostream>
#include <fstream>
int main()
{
char file[25];
std::cout << "***********************" << std::endl;
std::cout << "* G R A D E B O O K *" << std::endl;
std::cout << "***********************" << std::endl;
std::cout << "Please enter the name of the grade file: ";
std::cin >> file;
if (file)
std::cout << "Grade information read successfully..." << std::endl;
else
std::cout << "Grade information not read correctly..." << std::endl;
std::cout << "Menu" << std::endl;
std::cout << "----" << std::endl;
}
#include <iostream>
#include <fstream>
int main()
{
char file[25];
std::cout << "***********************" << std::endl;
std::cout << "* G R A D E B O O K *" << std::endl;
std::cout << "***********************" << std::endl;
std::cout << "Please enter the name of the grade file: ";
std::cin >> file;
std::ofstream file;
file.open();
if (file)
std::cout << "Grade information read successfully..." << std::endl;
else
std::cout << "Grade information not read correctly..." << std::endl;
std::cout << "Menu" << std::endl;
std::cout << "----" << std::endl;
}
#include <iostream>
#include <fstream>
#include <string>
int main()
{
std::string file;
std::cout << "***********************" << std::endl;
std::cout << "* G R A D E B O O K *" << std::endl;
std::cout << "***********************" << std::endl;
std::cout << "Please enter the name of the grade file: ";
std::cin >> file;
std::ifstream inFile;
inFile.open(file.c_str());
if (inFile)
std::cout << "Grade information read successfully..." << std::endl;
else
std::cout << "Grade information not read correctly..." << std::endl;
}
I am getting the error here:
inFile.open(file.c_str());
scratch that, i'm not getting an error now...weird, but every time it says my file is not read correctly, what could cause this?