簡體   English   中英

使用mingw64時,文件路徑應該使用A還是B

[英]When using mingw64, should the file path use A or B

I use mingw64 to write c programs on Windows 10. I heard that the c compiler is ported from Linux to Windows, and the separators used in the file path of Windows and Linux are different, so should I use "/" or "\"寫程序的時候?

始終使用/ The Windows API understands C:/ as well as C:\ while for Posix systems \ is a character like any other, so one directory can be actually be named foo\bar in such systems. 以可移植性為目標的程序使用/作為目錄分隔符。

除了 Ted Lyngmo 的回答, \有時用於轉義下一個字符,例如:在我編輯之前,您的問題沒有顯示\字符,“\”中的第二個“”顯示為“而不是 \”。

所以,使用/來避免混淆。

由於\發生的錯誤示例:

#include <stdio.h>

int main() {
    puts("\");
}

會在通常的編譯器中導致錯誤,說missing terminating " character

並且諸如C:\example\abc\x20類的路徑將變成亂碼,而我確信\x20將變成一個空格,並通過編譯器錯誤檢測。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM