Zasto koristis wchar_t* ?
1. S obzirom da vec upotrebljavas standardnu biblioteku koristi onda std::wstring.
2. Ne mogu se ispisivati unicode stringovi koristeci cout. Za njih se koristi wcout.
3. Ne moze se kastovanjem konvertovati obican string u unicode string, za to treba da se napise funkcija.
dakle nesto kao ovo:
Code:
#include <cstdlib>
#include <string>
#include <iostream>
#include <vector>
std::wstring string2wstring (const std::string& str) {
std::wstring result;
if (!str.empty()) {
std::vector<wchar_t> buffer(str.size());
std::size_t res = std::mbstowcs(&buffer[0],str.c_str(),str.size());
if (res > 0) {
result.assign(buffer.begin(),buffer.end());
}
}
return result;
}
Onda bi tvoj dalji kod izgledao malo drugacije:
Code:
int main(int argc, char* argv[])
{
if (argc < 7) {
std::cerr << "Greška" << std::endl;
}
for (int pos=1; pos < argc; ++pos) {
std::wcout << L"Argument " << pos << L": "
<<string2wstring(argv[pos]) << std::endl;
}
return EXIT_SUCCESS;
}
I da bi dobio wchar_t* od std::wstring dovoljno je da koristis c_str() dakle nesto kao ovo:
Code:
void nekafunkcija (wchar_t *param);
std::wstring w(L"aa");
nekafunkcija(w.c_str());
Tko leti vrijedi