C C++ Êä³öÖÐÎÄ¡¾×ª¡¿
1. wprintf
Q : sizeof(wchar_t) = ?
A : Ëæ±àÒëÆ÷²»Í¬¡£(ËùÒÔ:ÔÚÐèÒª¿çƽ̨µÄʱºò¾¡Á¿²»ÓÃwchar_t) vc : sizeof(wchar_t) = 2;
Q: ÔÚvcÖУ¬ÎªÊ²Ã´Ö±½ÓʹÓÃwprintf(L"²âÊÔ1234")»áûÓнá¹û
A: ûÓÐÉèÖúÃlocale,ÕâÑù×ö
setlocale(LC_ALL ,
"
chs
"
);
wprintf(L
"
%s
"
,L
"
²âÊÔ1234
"
);
»òÕß(¼ÙÉ赱ǰ»î¶¯codepageΪchs)
char
scp[
16
];
int
cp
=
GetACP();
sprintf(scp,
"
.%d
"
,cp);
setlocale( LC_ALL, scp );
wprintf(L
"
²âÊÔ1234
"
);
2. wcout
Ò»Ñù£¬²»¹ýÉ趨locale,ÇëÓÃstd::locale
locale loc(
"
chs
"
);
wcout.imbue(loc);
wcout
<<
L
"
²âÊÔ1234
"
<<
endl;
ÕâƪÎÄÕÂÓ¦¸ÃÊÇ[netsin
]µÄ³É¹û£¬ÎÒÇڿ죬¼ÇÏÂÀ´¡£
×¢£ºwprintfÊÇCµÄ±ê×¼¿âº¯Êý£¬µ«wcout²»ÊÇC++µÄ±ê×¼³ÉÔ±£¬C++ÖÐµÄ L"……" ÊÇ¿í×Ö·û£¬È´Î´±ØÊÇunicode×Ö·û£¬ÕâÓë±àÒëÆ÷ʵÏÖÏà¹Ø¡£
[ǬÀ¤Ò»Ð¦
]
˵£ºÎªÊ²Ã´ C/C++ ÓïÑÔ°Ñ L"xx" ¶¨ÒåΪÓÉʵÏÖ¾ö¶¨µÄÄØ£¿ÕâÏÔÈ»ÊÇΪÁË C/C++ µÄÆÕÊÊÐÔ¡¢¿ÉÒÆÖ²ÐÔ¡£Bjarne
µÄ¹ÛµãÈÏΪ£¬C++ µÄ·½Ê½ÊÇÔÊÐí³ÌÐòԱʹÓÃÈκÎ×Ö·û¼¯×÷Ϊ´®µÄ×Ö·ûÀàÐÍ¡£ÁíÍ⣬unicode
±àÂëÒѾ·¢Õ¹ÁËÈô¸É°æ±¾ÁË£¬ÊÇ·ñÄÜÓÀ¾ÃÊʺÏÏÂÈ¥Ò²²»µÃ¶øÖª¡£ÓÐ¹Ø unicode µÄÏêϸÂÛÊöÒÔ¼°ºÍÆäËü×Ö·û¼¯µÄ±È½Ï£¬ÎÒÍƼöÄã¿´¡¶ÎÞ·Ï»°xml¡·¡£
ÒÔÏÂÁ½¶Î´úÂëµÄÖ´Ðл·¾³ÊÇ windows xp professional Ó¢Îİ棬±àÒëÆ÷ÊÇ VS2005RTM¡£
// C
#include <stdio.h>
#include <locale.h>
int main( void )
{
setlocale( LC_ALL, "chs" );
//setlocale( LC_ALL, "Chinese-simplified" );
//setlocale( LC_ALL, "ZHI" );
//setlocale( LC_ALL, ".936" );
wprintf( L"Öйú" );
return 0;
}
// C++
#include <iostream>
#include <locale>
using namespace std;
int main( void )
{
locale loc( "chs" );
//locale loc( "Chinese-simpl
Ïà¹ØÎĵµ£º
ǰЩÌ죬±à³ÌÐòÊÇÓõ½Á˺ܾÃÒÔǰдµÄC³ÌÐò£¬Ïë°ÑÀïÃæµÄº¯ÊýÀûÓÃÆðÀ´£¬Á¬½Ó·¢ÏÖ³öÏÖÁËÕÒ²»µ½¾ßÌ庯ÊýµÄ´íÎó£º
ÒÔÏÂÊǼÙÉè¾ÉµÄC³ÌÐò¿â
CµÄÍ·Îļþ
/*-----------c.h--------------*/
#ifndef _C_H_
#define _C_H_
extern int add(int x, int y);
#endifCµÄÔ´Îļþ
/*-----------c.c--------------*/
int add(int x, in ......
ÓÉÓÚ³ÌÐòÔËÐÐʱռÓõÄÄÚ´æ¹ý´ó£¬ËùÒÔÏë°ì·¨¸ø³ÌÐòÊÝÉí¡£
ÔÚµ÷ÊÔÖз¢ÏֽṹÌåÕ¼ÓõÄsize¾¹È»ºÍÔ¤ÏëµÄ²»Ò»Ñù£¬ÔÀ´……
¿´¿´ÏÂÃæ½²µÄ°É£¬¿Ï¶¨»á²»Í÷´Ë¿´Å¶£¡
1,±ÈÈç:
struct{
short a1;
short a2;
short a3;
}A;
struct{
......
// Õª×Ô£ºWikipedia.org
CÓïÑԵıê×¼ÎÄÎļþÒªÇóÁËÒ»¸öƽ̨ÒÆÖ²CÓïÑÔµÄʱºòÖÁÉÙҪʵÏÖµÄһЩ¹¦Äܺͷâ×°µÄ¼¯ºÏ£¬³ÆΪ“±ê×¼¿â”£¬±ê×¼¿âµÄÉùÃ÷Í·²¿Í¨¹ýÔ¤´¦ÀíÆ÷ÃüÁî#include½øÐÐÒýÓá£
ÔÚC89±ê×¼ÖУº
01. <assert.h>
02. <ctype.h>
&nbs ......
Gcc¼ò½é
LinuxϵͳϵÄgcc£¨GNU C Compiler£©ÊÇGNUÍƳöµÄ¹¦ÄÜÇ¿´ó¡¢ÐÔÄÜÓÅÔ½µÄ¶àƽ̨±àÒëÆ÷£¬ÊÇGNUµÄ´ú±í×÷Æ·Ö®Ò»¡£gccÊÇ¿ÉÒÔÔÚ¶àÖÖÓ²Ìåƽ̨ÉϱàÒë³ö¿ÉÖ´ÐгÌÐòµÄ³¬¼¶±àÒëÆ÷£¬ÆäÖ´ÐÐЧÂÊÓëÒ»°ãµÄ±àÒëÆ÷Ïà±Èƽ¾ùЧÂÊÒª¸ß20%~30%¡£
gcc ±àÒëÆ÷Äܽ«C¡¢C++ÓïÑÔÔ´³ÌÐò¡¢»ã³Ìʽ»¯ÐòºÍÄ¿±ê³ÌÐò±àÒë¡¢Á¬½Ó³É¿ÉÖ´ÐÐÎļþ£¬Èç¹ûûÓи ......
1. ²ÉÓö̱äÁ¿¡£ÈçbData£¬unsigned char¡£
2. ÎÞ·ûºÅ±äÁ¿¡£51²»Ö§³Ö·ûºÅÔËËã¡£
3. ±ÜÃâʹÓø¡µãÖ¸Õë¡£¸¡µãÔËËãʱҪ½ûÖ¹Öжϡ£
4. &nb ......