Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3670120
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:19:33+00:00 2026-05-19T02:19:33+00:00

What do I have to do to make my program use a file that

  • 0

What do I have to do to make my program use a file that has been dragged and dropped onto its icon as a parameter?

My current main method looks like this:

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]);
    // ...

    cout << "\n" << "Programm finished...\n\n" << endl;

    // cin.ignore();
    return 0;
}

What I’d really like to be able to do is select 10 (or so) files, drop them onto the EXE, and process them from within my application.


EDIT:

The incomming parameter is used as filename, constructed in the cunstructor.

Converter::Converter(char* file) {
       // string filename is a global variable
   filename = file;
   myfile.open(filename.c_str(), ios_base::in);
}

The method where the textfile gets read:

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:
deleted

Update:
I got again to this point.

Actual Main method:

// File path as argument

int main(int argc, char* argv[]) {
if (argc < 2) {
cout
<< “ERROR: Wrong amount of arguments! Give at least one argument …\n”
<< endl;
cout << “\n” << “Programm closed…\n\n” << endl;
cin.ignore();
exit(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;
}

Actually the console window apears for maybe 0.5 sec and closes again.
It doen’t stop on any of my cin.ignore(); Maybe it doesn’t get there?

Can anyone help?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T02:19:33+00:00Added an answer on May 19, 2026 at 2:19 am

    Your program does not need to do anything special apart from handling command-line arguments. When you drag-drop a file onto an application in Explorer it does nothing more than to pass the file name as argument to the program. Likewise for multiple files.

    If all you expect is a list of file names, then just iterate over all arguments, do whatever you want with them and be done. This will work for zero to almost arbitrarily many arguments.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying, in vain, to make a program that reads text out
I need to make the program which have one form that contains PNG image
I have a Flash program that needs to make url requests to send data
I have written a C++ program that reads in a file and outputs the
I have a program that stores it's information in an XML file. This file
I have the following makefile that I use to build a program (a kernel,
I have a header file that has a number of declarations like this: extern
I have a configuration file that has variables and value separate by spaces. I
I have to make an uninformed search (Breadth-first-Search) program which takes two nodes and
I am new in java. I try to make a program and I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.