Lidar com acentos e cedilhas [C++]

toblesu

Power Member
Boas,

Na linguagem C, bastaria usar a nomenclatura char(135) para representar o 'ç'... Em C++ também é possível, mas também me disseram que utilizando os comandos

Código:
#include <windows.h>

main(){
SetConsoleCP(1252);
SetConsoleOutputCP(1252);

/* ... */
}


que bastaria.... o sistema reconheceria esses caracteres....
mas não estou a conseguir obter grandes resultados a esse nível!

Entretanto descobri outro código [ 28591 - ISO 8859-1 Latin 1; Western European (ISO)]

Código:
SetConsoleCP(28591);
SetConsoleOutputCP(28591);

mas este igualmente não produz efeitos!!

Será que me poderiam ajudar???

Obrigado.
 
Última edição pelo moderador:
Na função main coloca apenas:

Código:
	_tsetlocale(LC_ALL, _T("portuguese_portugal"));

Tens de fazer os seguintes includes:
Código:
#include <windows.h>
#include <tchar.h>

Cumps
 
Muito obrigado pela ajuda!!

Resultou!! :D

só fiquei com um problema, tinha feito um limite, com caracteres ASCII, apenas para limitar a área de trabalho (coisa de estética), haveria alguma forma de voltar a colocar esse rebordo? Já que com a linha

_tsetlocale(LC_ALL, _T("portuguese_portugal"));

esses caracteres foram convertido noutros que não têm nada a ver!

Em todo o caso, muito obrigado mais uma vez!
 
Última edição:
SetConsoleOutputCP() changes the displaying of extended characters in a console window only if the current font is a fixed-pitch Unicode font. It does not effect the displaying of extended characters of the console font named "Raster Font."

http://support.microsoft.com/default.aspx?scid=kb;en-us;Q99795


Se se mudar a fonte da consola para lucida console:

Código:
#include <iostream>
[B]#include <windows.h>[/B]

using namespace std;

int main()
{

[B]SetConsoleOutputCP(1252);[/B]

    cout << "Áá Çç!";
    cin.get();
    return 0;
}
Irá imprimir exactamente: Áá Çç!

-----------------------------------------------------------------------------------------

Alright... I've never used Unicode on the Win32 console before, but apparently it doesn't play nice with C++.

If you save your files as UTF-8
without the BOM marker g++ will pick up on it just fine.

If you want Unicode output, the cout and wcout streams libraries are
not the correct things to use. (There isn't one. Alas.) Both output "narrow" characters. The difference is that wcout narrow()s the wchar_ts it gets whereas cout just barfs on them.

You can write Unicode to the console via the standard streams if you are willing to write your own streambufWriteConsoleW()
http://msdn.microsoft.com/en-us/library/ms687401(VS.85).aspx

There is one caveat: the Console "Prompt Properties" Font tab must list Lucida Console as the active font.
(If you know what you are doing then you
class that uses the correct output methods. The trick (whether you write your own streambuf or not) is to use the <windows.h> function can use others: http://blogs.msdn.com/oldnewthing/archive/2007/05/16/2659903.aspx )

So far I haven't figured out how to set that programmatically yet, but if I do I'll let you know.



fonte: http://www.cplusplus.com/forum/general/3722/

-----------------------------------------------------------------------------------------

Use
WriteConsoleW --> for Unicode
WriteConsoleA--> for ANSI


fonte: http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/a6d307e6-f612-4ecb-9cf2-ab4f1de3f25a/
 
Última edição:
Back
Topo