【发布时间】:2015-12-24 18:21:36
【问题描述】:
所以我知道怎么做,我只是想让它打开文件而不指定路径。
例如:我在里面
C:\Users\\(me)\Desktop\Projects\BCs\BSCV2\bin\Debug\BSC.exe
但是如果我把它给一个朋友,他有一个不同的用户名,例如(him),所以即使他把它放在他的桌面上,该命令也无法执行,因为路径不再有效.
这是部分代码:
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
int a;
cout << endl;
cout << " This window is used for launching the programs." << endl;
cout << " Type in the number of the program you want to use and press Enter." << endl;
cout << endl;
cout << " 1) BSCV2 << endl;
cout << endl;
cout << " "; cin >> a; cout << endl;
cout << endl;
if (a == 1){
system ("start C:\\Users\\(me)\\Desktop\\Projects\\BCs\\BSCV2\\bin\\Debug\\BSCV2.exe");
system ("pause");
}
return 0;
}
我怎样才能让它在任何人的电脑上运行,不管他们把它放在哪里? 另外,如果您可以重写我的代码作为示例,我将不胜感激。
【问题讨论】:
-
我认为
cout << " 1) BSCV2 << endl;不会编译,是吗? -
我一定是不小心删除了最后的“。我的意思是
cout << " 1) BSCV2" << endl; -
当您从 IDE 逐字复制/粘贴测试用例时,“意外删除”字符令人印象深刻。
-
我实际上删掉了一些代码,因为它是相同的,但会(至少应该)打开另一个可执行文件。
标签: c++