.... and have the prog. open it. My question is, is there method of doing that and if so,
using what library?
I don't want any user input for this particular utility, just drag n' drop any file onto the console window.
.... and have the prog. open it. My question is, is there method of doing that and if so,
using what library?
I don't want any user input for this particular utility, just drag n' drop any file onto the console window.
Thanks, though I was referring to something much simpler; a console program. ie:
I know that it can be done (but I don't know how) and I hope that it doesn't turn out to be some convoluted mess of code.Code:ifstream fin(getFile, ios::in | ios::beg ); // whereas 'getFile' is a wildcard; any file dropped onto window
Well, just dragging shell objects onto the console window effectively pastes their filename, which can be read by standard means. And then you can just use the ifstream on what you have read. Very simple really.
If you mean drag and drop the file onto the executable icon, then you're talking about parameters. But I don't think that's what you're talking about.
"If you tell the truth, you don't have to remember anything"
-Mark Twain
I'm must be dumber than I thought since either I'm failing to get my point across or I'm misunderstanding the answers to my question.Originally Posted by Tonto
if;
... simply dropping any file onto the console window would effectively paste the fileName, then wouldn't the cout << FileName; spit out that file's name...?Code:char FileName[256]; ifstream fin(FileName, ios::in | ios::beg ); std::cout << FileName;
Code:char FileName[256]; // Now drop fiole onto window, opeartor >> will pick it up std::cin >> FileName; ifstream fin(FileName, ios::in | ios::beg ); std::cout << FileName;
Thanks, but it doesn't seem to work.
Code:int main () { char FileName[256]; // Now drop file onto window, operator >> will pick it up std::cin >> FileName; ifstream fin(FileName, ios::in | ios::beg ); std::cout << FileName; // does not print filename // safe to assume file isn't being id'd. cin.get(); fin.close(); return 0; }
try it like this
Code:#include <iostream> #include <string> int main () { std::string FileName; std::getline(std::cin, FileName); // NOW drop the file into the console window std::cout << FileName; // prints filename std::cin.get(); std::cin.ignore(); return 0; }
"I saw a sign that said 'Drink Canada Dry', so I started"
-- Brendan Behan
Free Compiler: Visual C++ 2005 Express
If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?
> Thanks, but it doesn't seem to work.
What are you trying to do - drop the files onto an executable in explorer, then explorer launches that program with the files as parameters?
If so, look at argc and argv in main()
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Originally Posted by ChaosEngine
Thanks, Chaos. That somewhat works, still have to actually open console window and then drop the file. I'll go with that until I can discover just how to drop file onto the exe. window and have the file registered. Meanwhile, I'll continue on with the code that I do know how to write.
I've looked at argc/argv main, but can't really figure out how that can be used to automatically pick up and open any file simply by the drop on an unopened exe. window. My last computer was a tandy1000 and coding back then was mostly limited to Dos so bear with me if I seem a little behind the times. I'm mostly doing this (coding stuff) to keep the old grey matter; use it or lose it as they say (whoever the hell they are). Anyways, if you have an example, that'd be appreciated since what I've read thru on the net doesn't seem to supply the answer. Thanks for the input.Originally Posted by Salem
By this do you mean automatically pickup any type of file such as a bitmap, text, MS Doc file etc. AND open it? In other words, have the console executable properly open the file regardless of the file type that is dropped on it?automatically pick up and open any file
Yes, exactly. Regardless of name or type, have that file opened on drop and allow following code to run (no user input at all).Originally Posted by BobS0327
so, instead of f.open ("thisfile.txt", ios::in) needing to be written out as code, a wildcard entry such as (anyfile, ios::in).
Well that depends what you mean by "open".
Now if you want to do something different with BMP, DOC, TXT whatever, then that's up to you.Code:int main ( int argc, char *argv[] ) { for ( int i = 1 ; i < argc ; i++ ) { cout << argv[i] << endl; // now do f.open(argv[i] etc etc } system("pause"); return 0; }
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Thank you, gentlemen (for your patience, in particular). With your help, I think I've got it all straight in my head now. For a change, the remainder of my code seems to be going rather smoothly.