relative path!?
hey all
sry but my english is very bad but i try it!
i have a program that copies some files from the folder where you start the program. how can i write a relative path?
such as
|
char src[100]="oemcopier/mm/oemlogo.bmp";
|
and not like
|
char src100]="c://oemcopier/mm/oemlogo.bmp";
|
??
thanks at all
greetz chrigu
Last edited on
The first element of argv always contains the name of the program. You just need to look for the last \ and go from the beginning to there.
1 2 3 4 5 6 7 8 9 10
|
#include <iostream>
#include <string>
using namespace std;
int main (int argc, char** argv) {
string path = string(argv[0]);
int lastslash;
path = path.substr(0, path.rfind('\\'));
cout << path << endl;
}
|
Why dont you try som dos while your at it. here try this, ive even copied the directorys you have listed in to the sorce code
1 2 3 4 5 6 7 8 9 10 11
|
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
system("copy C:\OEMCOPIER\MM\OEMLOGO.BMP");
return EXIT_SUCCESS;
}
|
Topic archived. No new replies allowed.