私はいくつかのVS 2015 C++コードをAndroid Studio C++コードに変換しようとしています。WCHARとwchar_tを一般的なものに置き換える
My機能は、次のようになります。
int size = 0;
int len = 0;
fread(&size,sizeof(int),1,g_File);
#ifdef VERBOSE
printf("fullSentences size = %d\n",size);
#endif
int i1 = 0;
int i2 = 0;
int i3 = 0;
for(int i = 0; i < size; i++)
{
fread(&len,sizeof(int),1,g_File);
wchar_t *buff = new WCHAR[len+1];
fread(buff,sizeof(WCHAR),len,g_File);
buff[len]=0;
fread(&i1,sizeof(int),1,g_File);
fread(&i2,sizeof(int),1,g_File);
fread(&i3,sizeof(int),1,g_File);
fullSentences.Add(buff,i1,i2,i3);
delete buff;
#ifdef VERBOSE
FullSentence fs = fullSentences.Content().back();
printf("%s\t%d\t%d\n",fs.Text.c_str(),fs.ByteStart,fs.ByteCount);
#endif
}
私は移植容易にするためにはWCHARとwchar_tを取り除くしたいと思います。
誰かがこれらの代替品を提案できますか? 可能であれば、wchar_tが何であるかをAndroid Studioに伝える必要はありません。
ありがとうございます。
編集:ここでは
は、クラス情報は次のとおりです。
//
// -------------------- clsFullSentences -----------------------------
//
vector<FullSentence> &clsFullSentences::Content()
{
return m_content;
}
vector<wstring> &clsFullSentences::CleanLower()
{
return m_sCleanLower;
}
void clsFullSentences::LoadSerializedFullSentences(string uFile)
{
if (!fileExists(stringToWString(uFile)))
{
DebugBreak();
}
FILE* inFile = fopen(uFile.c_str(), "rb");
wchar_t signature[2];
fread(signature, sizeof(wchar_t), 1, inFile);
wstring wline;
//read how many possibleresults we have
getLineW(inFile, wline);
unsigned int count=_wtoi(wline.c_str());
for (unsigned int i = 0; i < count; i++)
{
FullSentence st;
getLineW(inFile,wline);
st.Text = wline;
//getLineW(inFile,wline);
st.Emotion =0;// _wtoi(wline.c_str());
getLineW(inFile,wline);
st.ByteStart = _wtoi(wline.c_str());
getLineW(inFile,wline);
st.ByteCount = _wtoi(wline.c_str());
m_content.push_back(st);
}
fclose(inFile);
}
void clsFullSentences::Add(wstring text, int i1, int i2, int i3)
{
FullSentence fs;
fs.Text = text;
fs.Emotion = i1;
fs.ByteStart = i2;
fs.ByteCount = i3;
m_content.push_back(fs);
wstring sClean;
sClean=StripPuncToLower(text);
m_sCleanLower.push_back(sClean);
}
bool getLineW(FILE *inFile, wstring &result)
{
wchar_t data[2] = { 0, 0 };
result = L"";
do
{
fread(data, sizeof(wchar_t), 1, inFile);
if (data[0] > 0)
{
if (data[0] != 13)
{
if (data[0] != 10)
{
result += data;
}
else
{
break;//10 is the end of the line
}
}
}
} while (!feof(inFile));
if (result.size() > 0)
{
return true;
}
else
{
return false;
}
}
情報が不十分です:クラス定義を含む 'fullSentences'の宣言が必要です。 Windowsではwchar_tが2bytesだから、u/int16_tで置き換えることができますが、動作する保証はありません(fullSentencesはwchar_tバッファを受け取り、std :: stringのようなものを抽出できます)。 –
@AdrianColomitchiありがとう、私はそれを追加しました。 – tmighty
Unicode文字列を処理する唯一の移植可能な方法は、UTF-8でUTF-8を格納してからUTF-8をコードのwchar_tに変換することです。 –