1
#include <sstream>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <windows.h>


using namespace std;
int main() {
  SetConsoleOutputCP(CP_UTF8);
  wstringstream wss;
  wchar_t buff[256];
  FILE *in;
  if(!(in = _wpopen(L"dir %windir%", L"r"))) { return 1; }
  while(!feof(in)) {
    if (fgetws(buff, sizeof(buff), in)!=NULL){
      wss << buff;
    }
  }
  pclose(in);
  wstring wstr;
  wstr = wss.str();
  wcout << wstr.c_str();
}

効果は次のようになります。

[...]

2011-04-10  14:11    <DIR>          .
2011-04-10  14:11    <DIR>          ..
2011-04-10  14:11    <DIR>          system32
2011-04-10  14:11    <DIR>          system
2011-04-10  14:11    <DIR>          repair
2011-04-10  14:11    <DIR>          Help
2011-04-10  14:11    <DIR>          Config
2011-04-10  14:11    <DIR>          Cursors
2011-04-10  14:11    <DIR>          Media
2011-04-10  14:11    <DIR>          java
2011-04-10  14:11    <DIR>          Web
2011-04-10  14:11    <DIR>          addins
2012-06-09  11:29             2

ファイルの終わりの文字が何らかの形で文字列に渡されているようです...私にはわかりません。しかし、エンコーディングを1バイトに戻すと、すべて正常に動作します..

ここで一部の関数をマルチバイトの代替に変更するのを忘れたのかもしれません。

4

0 に答える 0