'wstring_convert' was not declared in this scope

0

Jak użyć 'wstring_convert' w Dev-C++ wiem, że to działa w Visual Studio ale wolał bym użyć go w Dev-C++
user image

#include <iostream>
#include <bits\codecvt.h>

using namespace std;

int main(){
	string narrow_utf8_source_string = "help";
	wstring_convert<codecvt_utf8_utf16<wchar_t>> converter;
	wstring wide = converter.from_bytes(narrow_utf8_source_string);
	wcout << wide << endl;
}
2

Włącz C++11, #include <locale>

0

Dalej to nie pomaga zrobiłem wszystko co napisałeś :(

user image

1
#include <iostream>
#include <codecvt>
#include <string>
0

@carlosmay dodałem te include i dalej ten sam błąd zdaje mi się, że ten Dev-C++ tak ma pewnie brakuje tych class w codecvt i nie da się skompilować :(

0

How can I compile C++11 code with Orwell Dev-C++?

For non-project compilations, go to: Tools >> Compiler Options >> (select your compiler) >> Settings >> Code Generation >> (set 'Language standard' to a C++11 option)
For project compilations, go to: Project >> Compiler >> Code Generation >> (set 'Language standard' to a C++11 option)

Ogólnie nie używam dev'a, ale kiedyś słyszałem, że może nie obsługiwać flag C++11.
Spróbuj ustawić C++11 w opcjach kompilatora. Link i cytat wyżej.

0

Dev-C++ używa TDM-GCC i obsługuje C++11 http://forums.codeblocks.org/index.php?topic=16866.0

Przy kompilacji widać że brakuje mu wstring_convert pobieram teraz Codeblock i zobacze czy w nim można kod skompilować (kompilator MinGW)

0

W C::B też nie da się skompilować kodu :(

user image

0

No to dodałem co nieco teraz mam inny problem kod:

#include <fstream>
#include <bits\codecvt.h>

using namespace std;

enum codecvt_mode {
    consume_header = 4,
    generate_header = 2,
    little_endian = 1
};

template<
    class Codecvt,
    class Elem = wchar_t
>class wstring_convert{};

template<
    class Elem,
    unsigned long Maxcode = 0x10ffff,
    codecvt_mode Mode = (codecvt_mode)0
>class codecvt_utf8_utf16 : public _STD codecvt<Elem, char, StateType>

int main() {
	string narrow_utf8_source_string = "help";
	wstring_convert<codecvt_utf8_utf16<wchar_t>> converter;
	wstring wide = converter.from_bytes(narrow_utf8_source_string);
	wprintf(L"%s", wide.c_str());
}

user image

Pomógłbyś?

2

Dlaczego nikt nie odpowiada w moim wątku? - szczególnie punkt 5.

twoja deklaracja szablonu klasy nigdzie się nie kończy i nie ma ciała. Czym jest _STD?

0
public _STD codecvt<Elem, char, StateType>

niby co to jest to _STD? w ogole co to ma robic? a raczje co chcesz osiagnac?

1

Dlaczego redefiniujesz elementy biblioteki standardowej? http://en.cppreference.com/w/cpp/locale/codecvt_utf8_utf16 Nie masz ich bezmyślnie przeklejać do kodu, tylko używać w razie potrzeb.

Ten wątek nadaje się do Newbie

0

Redefiniuje ją bo jej nie ma w ogóle w żadnych bibliotekach

user image

#include <fstream>
#include <bits\codecvt.h>
#include <locale>

using namespace std;

enum codecvt_mode {
    consume_header = 4,
    generate_header = 2,
    little_endian = 1
};

template<
    class Codecvt,
    class Elem = wchar_t
>class wstring_convert{};

template< class Elem,
          unsigned long Maxcode = 0x10ffff,
          codecvt_mode Mode = (codecvt_mode)0 >
class codecvt_utf8_utf16 : public codecvt<Elem, char, mbstate_t>{};;

int main() {
	string narrow_utf8_source_string = "help";
	wstring_convert<codecvt_utf8_utf16<wchar_t>> converter;
	wstring wide = converter.from_bytes(narrow_utf8_source_string);
	wprintf(L"%s", wide.c_str());
}

Zostały tylko dwa błędy :\

3
  1. Masz link http://en.cppreference.com/w/cpp/locale/codecvt_utf8_utf16
  2. klikasz
  3. czytasz "Defined in header <codecvt>"
  4. ?????
  5. profit!
1

Ty nie masz bladego pojecia co robisz a nie, ze nie ma

uruchom sobie kod w linku od @kq

#include <fstream>
#include <iostream>
#include <string>
#include <locale>
#include <codecvt>
 
int main()
{
    std::ofstream("text.txt") << u8"z\u6c34\U0001d10b";
 
    std::wifstream file1("text.txt");
    file1.imbue(std::locale("en_US.UTF8"));
    std::cout << "Normal read from file (using default UTF-8/UTF-32 codecvt)\n";
    for (wchar_t c; file1 >> c; )
        std::cout << std::hex << std::showbase << c << '\n';
 
    std::wifstream file2("text.txt");
    file2.imbue(std::locale(file2.getloc(), new std::codecvt_utf8_utf16<wchar_t>));
    std::cout << "UTF-16 read from the same file (using codecvt_utf8_utf16)\n";
    for (wchar_t c; file2 >> c; )
        std::cout << std::hex << std::showbase << c << '\n';
} 
0
#include <fstream>
#include <iostream>
#include <string>
#include <locale>
#include <bits\codecvt.h>
 
using namespace std;

template< class Codecvt,
          class Elem = wchar_t,
          class Wide_alloc = std::allocator<Elem>,
          class Byte_alloc = std::allocator<char> >
class wstring_convert;
 
int main() {
    string narrow_utf8_source_string = "help";
    wstring_convert<codecvt_utf8_utf16<wchar_t>> converter;
    wstring wide = converter.from_bytes(narrow_utf8_source_string);
    wprintf(L"%s", wide.c_str());
}

user image

Jak dodam std:: do codecvt_utf8_utf16 to mam jest taki błąd 'codecvt_utf8_utf16' is not a member of 'std'

1

http://4programmers.net/Forum/1248497
Zwróć szczególną uwagę na punkt trzeci.

1

Zaktualizuj kompilator do wersji "tdm -gcc 5.1.0.3.exe" i włącz minimum C++11 w opcjach kompilatora. W tej wersji zadziała twój pierwotny kod.

0

@carlosmay Aktualziacja kompilatora nic nie dała dalej to samo nie da się skompilować tego cholerstwa
user image

0

No dobra wreszcie się udało ale czy ten kod jest prawidłowy?

#include <fstream>
#include <locale>
#include <bits\codecvt.h>

using namespace std;

enum codecvt_mode {
    consume_header = 4,
    generate_header = 2,
    little_endian = 1
};

template< class Elem,
          unsigned long Maxcode = 0x10ffff,
          codecvt_mode Mode = (codecvt_mode)0 >
class codecvt_utf8_utf16 : public std::codecvt<Elem, char, std::mbstate_t>{};;

int main() {
    string narrow_utf8_source_string = "help";
    wstring_convert<codecvt_utf8_utf16<wchar_t> > converter;
    wstring wide = converter.from_bytes(narrow_utf8_source_string);
    wprintf(L"%s", wide.c_str());
}

I dziękuję za pomoc pewnie bez was by mi się nie udało :)

1

Działający kod z pierwszego posta w Code::Blocks.

#include <iostream>
#include <string>
#include <codecvt>
#include <locale>

using namespace std;

int main(){
    string narrow_utf8_source_string = "help";
    wstring_convert<codecvt_utf8_utf16<wchar_t>> converter;
    wstring wide = converter.from_bytes(narrow_utf8_source_string);
    wcout << wide << endl;
}

Widocznie nieprawidłowo wykonana była aktualizacja:

  • Pobierz: tdm-gcc.5.1.0.3.exe
  • Zainstaluj (gdzie chcesz).
  • Dodaj nowy kompilator do Code::Blocks (zastąp nim obecny)
    **Code::Blocks->Settings->Compiler->Toolchain executables-> tutaj podajesz ścieżkę do nowego kompilatora (np. C:\TDM-GCC-32. Pozostałe elementy kompilatora powinny dodać się automatycznie (robiłem to ręcznie dla pewności).
  • Settings->Compiler->Compiler Settings-> odszukujesz "Have g++ follow the C++14ISO C++ language standard [-std=c++14] i zaznaczasz (badź C++11 jeśli nie potrzeba C++14).

1 użytkowników online, w tym zalogowanych: 0, gości: 1