Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
对TCHAR argv[0]使用tprintf并获得问号 自从我在C++开发以来,已经有10年了。我试图通过命令行接受一个值,并将其传递给类构造函数 #include "stdafx.h" #ifdef _WIN32 #include <windows.h> #include "WinFolderMonitor.h" #elif __APPLE__ #elif __linux__ #elif __unix__ #endif int main(int argc, TCHAR *argv[]) { if (argc != 2) { _tprintf(TEXT("Usage: %s <dir>\n"), argv[0]); return 0; } #ifdef _WIN32 WinFolderMonitor* folderMonitor = new WinFolderMonitor(argv[1]); #endif folderMonitor->WatchDirectory(); return 0; } #包括“stdafx.h” #ifdef_WIN32 #包括 #包括“WinFolderMonitor.h” #埃利夫苹果__ #埃利夫linux__ #伊里夫__ #恩迪夫 int main(int argc,TCHAR*argv[]) { 如果(argc!=2) { _tprintf(文本(“用法:%s\n”),argv[0]); 返回0; } #ifdef_WIN32 WinFolderMonitor*folderMonitor=新的WinFolderMonitor(argv[1]); #恩迪夫 folderMonitor->WatchDirectory(); 返回0; }_C++_Visual Studio - Fatal编程技术网 WatchDirectory(); 返回0; },c++,visual-studio,C++,Visual Studio" /> WatchDirectory(); 返回0; },c++,visual-studio,C++,Visual Studio" />

对TCHAR argv[0]使用tprintf并获得问号 自从我在C++开发以来,已经有10年了。我试图通过命令行接受一个值,并将其传递给类构造函数 #include "stdafx.h" #ifdef _WIN32 #include <windows.h> #include "WinFolderMonitor.h" #elif __APPLE__ #elif __linux__ #elif __unix__ #endif int main(int argc, TCHAR *argv[]) { if (argc != 2) { _tprintf(TEXT("Usage: %s <dir>\n"), argv[0]); return 0; } #ifdef _WIN32 WinFolderMonitor* folderMonitor = new WinFolderMonitor(argv[1]); #endif folderMonitor->WatchDirectory(); return 0; } #包括“stdafx.h” #ifdef_WIN32 #包括 #包括“WinFolderMonitor.h” #埃利夫苹果__ #埃利夫linux__ #伊里夫__ #恩迪夫 int main(int argc,TCHAR*argv[]) { 如果(argc!=2) { _tprintf(文本(“用法:%s\n”),argv[0]); 返回0; } #ifdef_WIN32 WinFolderMonitor*folderMonitor=新的WinFolderMonitor(argv[1]); #恩迪夫 folderMonitor->WatchDirectory(); 返回0; }

对TCHAR argv[0]使用tprintf并获得问号 自从我在C++开发以来,已经有10年了。我试图通过命令行接受一个值,并将其传递给类构造函数 #include "stdafx.h" #ifdef _WIN32 #include <windows.h> #include "WinFolderMonitor.h" #elif __APPLE__ #elif __linux__ #elif __unix__ #endif int main(int argc, TCHAR *argv[]) { if (argc != 2) { _tprintf(TEXT("Usage: %s <dir>\n"), argv[0]); return 0; } #ifdef _WIN32 WinFolderMonitor* folderMonitor = new WinFolderMonitor(argv[1]); #endif folderMonitor->WatchDirectory(); return 0; } #包括“stdafx.h” #ifdef_WIN32 #包括 #包括“WinFolderMonitor.h” #埃利夫苹果__ #埃利夫linux__ #伊里夫__ #恩迪夫 int main(int argc,TCHAR*argv[]) { 如果(argc!=2) { _tprintf(文本(“用法:%s\n”),argv[0]); 返回0; } #ifdef_WIN32 WinFolderMonitor*folderMonitor=新的WinFolderMonitor(argv[1]); #恩迪夫 folderMonitor->WatchDirectory(); 返回0; },c++,visual-studio,C++,Visual Studio,然而,我得到的结果并不像预期的那样。相反,我收到了一堆问号,我通常会将其归因于一些编码问题,但我相信我已经正确地设置了项目来缓解这一问题 C:\SVN\monitor.exe Usage: ?????????e????? <dir> C:\SVN\monitor.exe 用法:???e????? 根据我的理解,我应该看到应用程序文件名。但是我得到了一大堆的问号。我已将项目设置为在Visual Studio中使用“Unicode”。使用\u tmain而不是main。如果定义了UN

然而,我得到的结果并不像预期的那样。相反,我收到了一堆问号,我通常会将其归因于一些编码问题,但我相信我已经正确地设置了项目来缓解这一问题

C:\SVN\monitor.exe
Usage: ?????????e????? <dir>
C:\SVN\monitor.exe
用法:???e?????

根据我的理解,我应该看到应用程序文件名。但是我得到了一大堆的问号。我已将项目设置为在Visual Studio中使用“Unicode”。

使用
\u tmain
而不是
main
。如果定义了UNICODE,
\u tmain
将成为
wmain(int-argc,wchar\u t*argv[])的宏。

另见

int\u tmain(int-argc,TCHAR*argv[]
{
如果(argc!=2)
{
_tprintf(文本(“用法:%s\n”),argv[0]);
返回0;
}
返回0;
}

这通常是为了家庭作业。除非您也针对Windows 98,否则没有必要使此ANSI兼容。否则,您可以只使用UNICODE版本,例如
const wchar\u t*text=L“text”等等。

我想说,很明显,ASCII和Unicode之间不匹配
tprintf
\u MBCS
\u UNICODE
\u UNICODE
控制。仔细检查那些#定义。可能相关:所有那些
tchar
废话都是为了支持Windows95。既然这已经无关紧要了,那就假设Unicode来编写代码。@AlanStokes真的吗?因此,请坚持使用
wchar\u t
?是的。作为一个额外的好处,通过使用标准设施,您的代码天生就更易于移植。感谢您的解释。当我需要将它移植到Linux时会发生什么?我想这从一开始就是我主要关心的问题,而且由于
wmain
似乎是特定于VS/Windows的,因此会缺少一些可移植性。在Linux环境中,如何使用
main
来支持
wchar\u t
\u tmain
\u printf
\u tcscpy\u s
等都是在
中定义的Microsoft宏。这会变得非常混乱。对于Linux UT/8UF8/ANSI,应该使用C++函数 STD::String ,而<>代码> STD::WString  Windows UTF16。然后,根据系统的不同,您可以创建自己的宏
t字符串
,以使用其中一个宏。在
TCHAR
+
tstring
上进行搜索。避免使用C风格的函数,如
strcpy
int _tmain(int argc, TCHAR *argv[])
{
    if (argc != 2)
    {
        _tprintf(TEXT("Usage: %s <dir>\n"), argv[0]);
        return 0;
    }

    return 0;
}