Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
standard unicode i c++
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Polskie forum (Polish) Polish OTW
View previous topic :: View next topic  
Author Message
sherszen
Apprentice
Apprentice


Joined: 28 Jul 2006
Posts: 198

PostPosted: Mon Mar 10, 2008 10:07 pm    Post subject: standard unicode i c++ Reply with quote

Witam,

Mam problem z identyfikacją polskich znaków w standardzie utf8. System ma ustawione locale pl_PL-UTF-8.
Code:
LANG=pl_PL.UTF-8
LC_CTYPE="pl_PL.UTF-8"
LC_NUMERIC="pl_PL.UTF-8"
LC_TIME="pl_PL.UTF-8"
LC_COLLATE=pl_PL.UTF-8
LC_MONETARY="pl_PL.UTF-8"
LC_MESSAGES="pl_PL.UTF-8"
LC_PAPER="pl_PL.UTF-8"
LC_NAME="pl_PL.UTF-8"
LC_ADDRESS="pl_PL.UTF-8"
LC_TELEPHONE="pl_PL.UTF-8"
LC_MEASUREMENT="pl_PL.UTF-8"
LC_IDENTIFICATION="pl_PL.UTF-8"
LC_ALL=


Chciałem poznać kod znaku "ą" lub innego polskiego znaku diakrytycznego. Problem polega na tym, że nie mogę dojść do tego jaki to kod.
Code:
 wchar_t znak;
 wcin >> znak;
 wcout << (int)znak << endl;

Niestety tai kod zamiast zwrócić mi poprawną wartość znaku, wyświetla takie coś: -1080027514. Dla innych znaków, które nie są wpisywane z pomocą klawisza Alt, kody są poprawne. W czym problem?
Back to top
View user's profile Send private message
13Homer
Guru
Guru


Joined: 12 Jul 2005
Posts: 461

PostPosted: Tue Mar 11, 2008 6:13 am    Post subject: Reply with quote

Może w tym, że rzutujesz na inta a nie na unsigned inta?
_________________
Lenovo ThinkPad R61 / C2D@2.6.24 / nVidia Quatro NVS 140M / 2 GB RAM
Back to top
View user's profile Send private message
cinek810
Tux's lil' helper
Tux's lil' helper


Joined: 07 Jul 2007
Posts: 115

PostPosted: Tue Mar 11, 2008 1:56 pm    Post subject: Reply with quote

Pamiętam, że gdzieś czytałem o problemach z wcin i pobierniem znaków w utf-8, sprawa działą się pod FreeBSD, nie pamiętam niestety o jakie gcc chodziło..

Spróbuj wpisać do wchar w kodzie programu, zamiast pobietrac od usera.
Back to top
View user's profile Send private message
Arfrever
Bodhisattva
Bodhisattva


Joined: 29 Apr 2006
Posts: 2462
Location: Polska / Lenkija

PostPosted: Tue Mar 11, 2008 5:59 pm    Post subject: Reply with quote

Spróbuj z ICU ("dev-libs/icu").
ICU Documentation
u_getNumericValue
Back to top
View user's profile Send private message
sherszen
Apprentice
Apprentice


Joined: 28 Jul 2006
Posts: 198

PostPosted: Thu Mar 13, 2008 10:28 pm    Post subject: Reply with quote

Code:
int wybor;
      cin >> wybor;

      string nazwa_pliku = "";

      switch(wybor)
      {
         case 1 : cout << "jakis tekst" << endl;
             getline(cin, tekst);
             cout << endl;


Mam taki kod. Dlaczego w tym przypadku, nie mogę wpisać tekstu po wyświetleniu "podaj tekst", tylko od_razu pojawia się monit o podanie hasła? Instrukcja getline jest pomijana. Dlaczego?

Arfrever: Ortografia
Back to top
View user's profile Send private message
wodzik
l33t
l33t


Joined: 12 Jun 2005
Posts: 713
Location: Człuchów

PostPosted: Thu Mar 13, 2008 10:57 pm    Post subject: Reply with quote

probowales z klamrami?
_________________
:() { :|: & };: <- nie próbuj wpisywać tego w konsoli
Back to top
View user's profile Send private message
sebas86
Guru
Guru


Joined: 01 May 2005
Posts: 526
Location: Szczecinek / Szczecin

PostPosted: Fri Mar 14, 2008 6:43 am    Post subject: Reply with quote

sherszen wrote:
Code:
cin >> wybor;
[...]
getline(cin, tekst);
Instrukcja getline jest pomijana. Dlaczego?

Nie jest pomijana, tylko pierwszy cin zostawia coś w buforze (np. znak końca linii). Jedno z rozwiązań na czyszczenie bufora jakie podsunęło mi google to:
Code:
cin.ignore(100,'\n');

_________________
Nieważne jaka dystrybucja, ważne, że Linux!
Back to top
View user's profile Send private message
dziadu
Guru
Guru


Joined: 04 May 2006
Posts: 428
Location: Kraków/Darmstadt/Munich

PostPosted: Fri Mar 14, 2008 10:17 am    Post subject: Reply with quote

A
Code:
cout.flush();
nie wystarczy? Nie sprawdzałem, ale problem może też zdaje się być z buforami wyjściowymi.
I tak BTW: czy nie powinno sie pisać:
Code:
cout::flush();
cin::ignore();

?
Dawno już w C++ nie pisałem...
Back to top
View user's profile Send private message
cinek810
Tux's lil' helper
Tux's lil' helper


Joined: 07 Jul 2007
Posts: 115

PostPosted: Fri Mar 14, 2008 5:12 pm    Post subject: Reply with quote

dziadu.. nie powinno się

:: - to operator związany z przestrzeniami nazw, ewentualnie powinno się pisać:

Code:

std::cout.flush();
std::cin.ignore();


no i na pewno nie wystarczy wypisać na ekran wszystk z bufora, zeby opróżnić bufor wejściowy :)
Back to top
View user's profile Send private message
sherszen
Apprentice
Apprentice


Joined: 28 Jul 2006
Posts: 198

PostPosted: Sun Mar 16, 2008 9:35 pm    Post subject: Reply with quote

Mam nadzieje, ze to mój ostatni z problemów jeśli chodzi o c++. W jaki sposób w plikach tekstowych oznaczany jest koniec pliku? funkcja eof() nie wczytuje mi całego ciągu znaków do stringa. Wydaje mi się, że problem polega na znaku końca pliku, który być może znajduje się gdzieś w środkowej części pliku. Może się mylę? Miał ktoś już z tym problem? Pojemność stringa chyba nie ma tutaj znaczenia. Hmm słyszałem, ze nieograniczony może wczytać nawet i 2.5 GB tekstu.
Back to top
View user's profile Send private message
cinek810
Tux's lil' helper
Tux's lil' helper


Joined: 07 Jul 2007
Posts: 115

PostPosted: Sun Mar 16, 2008 11:01 pm    Post subject: Reply with quote

w c standard lib. jest takie makro EOF..

zwyczajowo jest to jakis kod ujemny, zalezy od systemu niby, ale najprawdopodobniej -1.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Polskie forum (Polish) Polish OTW All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum