Im trying to figure out how to read a file that is entered into the command line.
I tried using
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
int main(int argc, char *argv[])
{
std::string a;
int b, c, d;
std::cout << "please enter the name of the file: " << std::endl;
std::cin >> a;
std::cout << argv[1] << "\n" << argv[0];
std::fstream info(argv[1], std::ios::in);
info >> b >> c >> d;
std::cout << b << " " << c << " " << d;
system("pause");
EXIT_SUCCESS;
}
but it throws an out of bounds exception trying to access argv[1].
how would I access this normally? is there some trick I didnt learn?
the way our teacher explained this to us was that int main(int argc,char *argv[]) read inserted commands from the command line and that argv[0] was always the filename.