Trying to save to data in a file. But I cannot save to the directory with the Russian name. I have created two folders, one in Russian "Results", the other in English "DDR".
Saving to the English directory works great, but in the Russian directory it doesn't. I made a couple of "conclusions" to see the result. Here he is:

WE ARE HERE

file_name "C: /Works/untitled16/Results/2016-08-30_10-54-24.txt"

str d ??

fname C: /Works/untitled16/Result Results/2016-08-30_10-54-24.txt

Error save Re & Im!

END

You can switch to using Qt for working with files (QFile). But I would first try other techniques. For I would like to make friends with SI and Qt.

//проверка создания папки if (QFile().exists(trUtf8("Результаты"))) { qDebug() << "МЫ ТУТ "; } else { qDebug() << "Папочка не созданна "; return; } // тут полный путь файла , название файла // file_name = QDir::current().absolutePath() + "/" + "DDR" + "/" + QDateTime::currentDateTime().toString("yyyy-MM-dd_hh-mm-ss") + ".txt"; file_name = QDir::current().absolutePath() + "/" + QString::fromUtf8("Результаты").toLocal8Bit().data() + "/" + QDateTime::currentDateTime().toString("yyyy-MM-dd_hh-mm-ss") + ".txt"; // проверка как это будет выглядеть на СИ . Результат будет при выполнении всего этого блока (в результата последний вывод, после END) char str[255]; printf(str, "%s", qPrintable(file_name)); fflush(stdout); qDebug()<< "file_name " <<file_name; qDebug()<< "str " <<str; if(file_name.isEmpty()) { qDebug() << "хренька печенька "; return; } // перевод QString в char char fname[255]; sprintf((char*)fname,"%s",file_name.toLocal8Bit().data()); qDebug() << "fname " <<fname; FILE *fid=0; fid=fopen(fname, "wb"); if(fid) { fwrite("привет\n", strlen("привет\n"), 1, fid); fclose(fid); } else { qDebug() << "Error save Re & Im! " ; } qDebug() << "END"; 

// ------------------------------------------------ -------------

I tried to use _wfopen

 // тут сохраненине файла бинарника file_name = QDir::current().absolutePath() + "/" + "DDR" + "/" + QDateTime::currentDateTime().toString("yyyy-MM-dd_hh-mm-ss") + ".bin"; // file_name = QDir::current().absolutePath() + "/" + "Результаты" + "/" + QDateTime::currentDateTime().toString("yyyy-MM-dd_hh-mm-ss") + ".bin"; if(file_name.isEmpty()) { qDebug() << "хпреньа11 печенька "; return; } wchar_t fname[255]; swprintf(fname, L"%s",file_name.toLocal8Bit().data()); FILE *fid=0; fid = _wfopen(fname, L"wb");// L - необходим, ибо иначе это будет строка типа char. qDebug() << "K"; if(fid) { char buffer[] = { 'w' , 't' , 'f' }; fwrite(buffer , 1 , sizeof(buffer) , fid ); fclose(fid); qDebug() << "G"; } else { qDebug() << "Error save Re & Im! " ; } 

The result surprised me greatly. With the "Results" directory, it did not work at all, but with the "DDR" directory. I earned it, but I created in the program folder the file 㩃 圯 牯 獫 猯 桯 慲 彮 灷 灡 畫 畫 䐯 剄 ㈯ ㄰ ⴶ 㤰 ㄭ 弴 〭ⴷ㌵ 〭ⴷ㌵ 戮 湩.

Tell me how to create at least C ++ (you can download a library), how to save it to the Russian directory.

  • And what is written in errno after trying to open a file? ( cplusplus.com/reference/cerrno/errno ) Maybe you can use _wfopen because This method will work for both Japanese and Chinese .. - Unick
  • one
    printf (str, "% s", qPrintable (file_name)); - is it not a sprintf ()? - Vladimir Martyanov
  • I do not know, I did not check it, it is not critical. Likely sprintf () - timob256

0