我正在使用 fgetws 从文件中逐行获取一些字符串。我拥有的文件来自一个 popen 命令。这是代码片段:
FILE* pInstalledApps = popen( command.c_str(), "r" );
if( NULL != pInstalledApps )
{
wchar_t currentAppPath [kMaximumAppPathLength];
// Reading app paths one line at a time.
while ( ! feof (pInstalledApps) )
{
if ( fgetws ( currentAppPath, kMaximumAppPathLength, pInstalledApps) == NULL )
{
break;
}
wchar_t *pCharPos = NULL;
if ( ( pCharPos = wcschr( currentAppPath, L'\n' ) ) != NULL )
{
*pCharPos = L'\0';
}
std::wstring appPath( currentAppPath );
//Do something with the wstring
}
pclose( pInstalledApps );
}
当我得到的字符串 currentAppPath 具有宽字符字符串时,我得到的 appPath 没有预期的字符串。例如,如果我从 FILE 获得的字符串是10teciêênks
我的 appPath 变量,则将具有10tecieÌeÌnks
.