Skip to content
Snippets Groups Projects
Commit 6896b49e authored by Måns Fredriksson Franzén's avatar Måns Fredriksson Franzén
Browse files

initial commit

parent c547fe26
No related branches found
No related tags found
No related merge requests found
...@@ -12,5 +12,6 @@ int main(int argc, char** argv) ...@@ -12,5 +12,6 @@ int main(int argc, char** argv)
{ {
assert(argc==2); /* argv[1] is the destination file */ assert(argc==2); /* argv[1] is the destination file */
/* Your code here */ /* Your code here */
filesystem::copy(L"马Häst马.txt",argv[1]);
return 0; return 0;
} }
...@@ -5,5 +5,18 @@ int main(int argc, char **argv) ...@@ -5,5 +5,18 @@ int main(int argc, char **argv)
{ {
assert(argc==1); assert(argc==1);
/* Your code here. */ /* Your code here. */
char *str = "马Häst马.txt";
char *newfilename = "win32.txt";
int wchar_length = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0);
wchar_t wchar_buffer[wchar_length];
MultiByteToWideChar(CP_UTF8, 0, str, -1, wchar_buffer, wchar_length);
int wchar_length2 = MultiByteToWideChar(CP_UTF8, 0, newfilename, -1, NULL, 0);
wchar_t wchar_buffer2[wchar_length2];
MultiByteToWideChar(CP_UTF8, 0, newfilename, -1, wchar_buffer2, wchar_length2);
CopyFileW(wchar_buffer, wchar_buffer2, FALSE);
return 0; return 0;
} }
#include <locale.h>
#include <string>
#include <iostream>
#include <time.h>
using namespace std;
float foo(string str);
void baz(float num);
i
int main () {
setlocale(LC_NUMERIC, "sv_SE.UTF8");
setlocale(LC_ALL, "sve_SE.UTF8");
string number("1.2345");
string date("Fri Jul 5 05:04:02 2019");
float svNumber = foo(number);
baz(svNumber);
return 0;
}
float foo(string str){
locale::global(locale("en_US.UTF8"));
return stof(str);
}
void baz(float num){
locale::global(locale("sv_SE.UTF8"));
cout.imbue(locale());
cout << num << endl;
}
...@@ -15,9 +15,18 @@ ...@@ -15,9 +15,18 @@
*/ */
FILE* my_fopen(char *str, char *mode) FILE* my_fopen(char *str, char *mode)
{ {
#if defined(_MSC_VER) || defined(__MINGW32__) #if defined(_MSC_VER) || defined(__MINGW32__)
int wchar_length = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0);
wchar_t wchar_buffer[wchar_length];
MultiByteToWideChar(CP_UTF8, 0, str, -1, wchar_buffer, wchar_length);
int wmode_length = MultiByteToWideChar(CP_UTF8, 0, mode, -1, NULL, 0);
wchar_t wmode_buffer[wmode_length];
MultiByteToWideChar(CP_UTF8, 0, mode, -1, wmode_buffer, wmode_length);
/* Hint: You want to modify this code */ /* Hint: You want to modify this code */
return fopen(str, mode); return _wfopen(wchar_buffer, wmode_buffer);
#else #else
/* Linux handles UTF-8 by default */ /* Linux handles UTF-8 by default */
return fopen(str, mode); return fopen(str, mode);
......
The filename has symbols from another language in it. These symbols are non-ASCII characters. Therefore we convert to a stream of widechar characters (that are 16-bits wide) instead and print those. The widechar range contain these characters.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment