The new forums will be named Coin Return (based on the most recent vote)! You can check on the status and timeline of the transition to the new forums here.
The Guiding Principles and New Rules document is now in effect.
C++ Question (fstream and args)
Sir CarcassI have been shown the end of my worldRound Rock, TXRegistered Userregular
More like arghs. This may be a simple question, but does anyone know why double-clicking the exe of my program creates the output file as expected while dragging files onto it doesn't? Here is my code for reference:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main(int argc, char *argv[])
{
fstream output, input;
string h = "this is a test";
output.open("CombinedList.csv", fstream::out);
output.write(h.c_str(),h.size());
cout << "press any key...." << endl;
cin.get();
output.close();
return 0;
}
I haven't gotten to the meat to this yet because I can't figure out why it's not creating a file when I drag files onto it.
it's putting the file the current working directory, which is apparently different if you drag and drop a file onto the executable
Normally it'd be the same directory the program is in, but in the drag and drop case, a little bit of research indicates it would be your home directory (C:\Users\name or C:\Document and Settings\name) instead.
I'm a little curious why you are dragging files onto it if you're not actually looking at your command line, but perhaps that is a yet to be implemented feature for you.
End on
I wish that someway, somehow, that I could save every one of us
it's putting the file the current working directory, which is apparently different if you drag and drop a file onto the executable
Normally it'd be the same directory the program is in, but in the drag and drop case, a little bit of research indicates it would be your home directory (C:\Users\name or C:\Document and Settings\name) instead.
I'm a little curious why you are dragging files onto it if you're not actually looking at your command line, but perhaps that is a yet to be implemented feature for you.
The ultimate point of this exe is to merge 4 files into 1. The 4 files will be changing each week, so I want to be able to just drag and drop the current 4 onto it. But yeah, I haven't even gotten that far yet.
I just checked, and yep, it's putting it in my users folder. How is that even a good idea.
argv[0] should contain a path, but may not be useful. Unfortunately working with a file system is incredibly stupid with C++ at current unless you're using OS specific libraries or Qt/Boost.
not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
Yeah, argv[0] would have a path to the executable, but that isn't super reliable (although probably correct enough in this case). The GetModuleFileName() function will also do it, assuming you're on windows.
I wish that someway, somehow, that I could save every one of us
Posts
Normally it'd be the same directory the program is in, but in the drag and drop case, a little bit of research indicates it would be your home directory (C:\Users\name or C:\Document and Settings\name) instead.
I'm a little curious why you are dragging files onto it if you're not actually looking at your command line, but perhaps that is a yet to be implemented feature for you.
The ultimate point of this exe is to merge 4 files into 1. The 4 files will be changing each week, so I want to be able to just drag and drop the current 4 onto it. But yeah, I haven't even gotten that far yet.
I just checked, and yep, it's putting it in my users folder. How is that even a good idea.
Is there any way around that?
I also need it to strip out the first line from each file except the first one.
That doesn't seem to help, unfortunately.
If nothing else, I guess I can hardcode a location, but having it put in the working directory would be so much better.
argv[0] should contain a path, but may not be useful. Unfortunately working with a file system is incredibly stupid with C++ at current unless you're using OS specific libraries or Qt/Boost.
Though argv[0] can have relative paths. Which might be an issue with the drag and drop.
Thanks for all of the help so far!