What do I need to do so that my program uses a file that was dragged and dropped to its icon as a parameter?
My current main method is as follows:
int main(int argc, char* argv[]) { if (argc != 2) { cout << "ERROR: Wrong amount of arguments!" << endl; cout << "\n" << "Programm closed...\n\n" << endl; exit(1); return 0; } Converter a(argv[1]);
What I really would like to do is select 10 (or so) files, drop them onto an EXE, and process them from my application.
EDIT:
The incomming parameter is used as the file name created in the cunstructor.
Converter::Converter(char* file) {
Text File Reading Method:
string Converter::readTextFile() { char c; string txt = ""; if (myfile.is_open()) { while (!myfile.eof()) { myfile.get(c); txt += c; } } else { error("ERROR: can't open file:", filename.c_str()); } return txt; }
EDIT2: Cross Out
Update:
I got to this point.
Actual main method:
// File path as argument
int main (int argc, char * argv []) {if (argc <2) {sob & A; <"ERROR: wrong number of arguments! Give at least one argument ... \ n" & L; <cps; cout <"\ n" <"The program is closed ... \ n \ n" <<nbsp; cin.ignore (); output (1); return 0; }
vector<string> files; for (int g = 1; g < argc; g++) { string s = argv[g]; string filename = ""; int pos = s.find_last_of("\\", s.size()); if (pos != -1) { filename = s.substr(pos + 1); cout << "argv[1] " << argv[1] << endl; cout << "\n filename: " << filename << "\n pos: " << pos << endl; files.push_back(filename); } files.push_back(s); } for (unsigned int k = 0; k < files.size(); k++) { cout << "files.at( " << k << " ): " << files.at(k).c_str() << endl; Converter a(files.at(k).c_str()); a.getATCommandsFromCSV(); } cout << "\n" << "Programm finished...\n\n" << endl; cin.ignore(); return 0; }
In fact, the console window appears, perhaps for 0.5 seconds, and closes again.
It does not stop at any of my cin.ignore(); Maybe he didnβt get there?
Can anyone help?
c ++ windows parameters executable drag-and-drop
Beasly
source share