c++ - how to make input prompt for 7 column by ifstream -
i typed in file name want show on prompt screen says "'c:\test\sp.csv' not recognized internal or external command," though file available on path.
1 - why did error happen? how fix it?
c:\users\ms>c:\test\sp.csv 'c:\test\sp.csv' not recognized internal or external command, operable program or batch file.
2 - code below shows 1 column, if want input 7 columns, how edit code below?
how print out on prompt screen using ifstream 7 column header , price.
date open high low close volume adj close 6/21/2013 1588.62 1599.19 1577.7 1592.43 5797280000 1592.43 6/20/2013 1624.62 1624.62 1584.32 1588.19 4858850000 1588.19
int main(){ int open; string filename; cout <<"enter file name: "; getline(cin, filename); //c:\\test\\sp.csv ifstream infile(filename.c_str(), ios::in); while(!infile.eof()){ infile >> open; cout << open << endl; } infile.close(); system("pause"); return 0; }
thank kelly
looks you're on windows os
-
.csv
file extension not executable one. won't "executed", if present in current working directory/folder.
probably want .exe
, .com
or .bat
file.
here, in case think want .cpp 's executable command line argument.
may like
c:\users\ms>c:\test\sp.exe c:\test\sp.csv'
considering c++ file name sp.cpp
2 . looks want display out contents of sp.scv
you may want read header first (i.e titles), , read values. there lot of question asked on stackoverflow, related this, please refer them.
also proper formatting may want use std::setw