We're just getting more into functions and this is one of our programs that we have to do. It's apparently a familiar one with many program students. I keep trying to compile the code (I use visual studio 2012, if that's of any use to mention) but it will only give me "Press any key to continue..." and that will be the only line I will see in the command window.
I'm guessing the issue is that it wants an input file but just isn't getting one.
SO... here are my questions
1)How do I do input files and the like in visual studio
2)Is there anything about this code that I need to fix
#include <iostream>
#include <string>
#include <fstream>
int main()
{
// this is just an example of a complete path
// replace with the actual path to your input file
const std::string path_to_file =
"C:/Documents and Settings/karpl/UserData/bumpkin/bumpkin.in" ;
std::ifstream file(path_to_file) ;
if(file) std::cout << "opened the file successfully\n" ;
else
{
std::cerr << "error in opening file: " << path_to_file << '\n' ;
return 1 ;
}
// rest of main
}
Most likely your teacher accidentally taught you to use using namespace std; and forgot to teach you why it was bad: http://stackoverflow.com/q/1452721
Most likely your teacher accidentally taught you to use using namespace std; and forgot to teach you why it was bad: http://stackoverflow.com/q/1452721
Most likely he did (either that or the book we're having to use) We're expected to use usingnamespace std; and nothing else as far as I know. He also never taught us how to use input files in visual studio 2012. It's an online class, and he posted the wrong video about it.