![](/img/trans.png)
[英]Why doesn't Qt recognize my header file? cannot open include file No such file or directory
[英]Why doesn't this open the file in the directory of the program?
我有這個簡短的程序:
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
int main (int argc, char * argv[]) {
std::string homedir = std::getenv("HOME");
std::string filename = argc > 1 ? argv[1] : (homedir + "/" + "file");
std::cout << homedir << std::endl;
std::cout << filename << std::endl;
std::fstream file;
file.open(filename, std::ios::out);
file << "Yo yo waddup" << std::endl;
file.close();
return 0;
}
當我不提供任何參數時,它將在用戶的主目錄中打開一個文件。 那當然是有道理的。 但是當我從這樣的不同目錄運行它時:
$ ./folder/hometest examplefile
該程序在我的當前目錄而不是該程序所在的目錄中創建“ examplefile”。
為什么會這樣呢?
為什么會這樣呢?
該程序的行為與預期的一樣。
相對於當前工作目錄而不是可執行文件所在的位置打開文件。
如果不是那樣的話
以上都不是理想的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.