ɾ³ýc/c++Ô´³ÌÐòÖеÄ×¢ÊÍ
ÌâÄ¿£º±àдһ¸ö³ÌÐò£¬ÓÃÓÚ´¦Àíc/c++Ô´³ÌÐò£¬½«Ô´³ÌÐòÖеÄ×¢ÊͲ¿·ÖÈ¥µô
ÊäÈ룺c/c++ÎļþÃû
Êä³ö£º´¦ÀíºóµÄ³ÌÐòÔ´Îļþ
³ÌÐòα´úÂëÈçÏ£º
c1,c2:char
tag:int
a:¶ÁÈëÒ»¸ö×Ö·û´æÈëc1
if tag==0 //¶ÁÈë×Ö·û²»ÊÇ×¢ÊÍ
if c1=='/' //¿ÉÄÜÊÇ×¢Êͱê¼Ç
¶ÁÈëÒ»¸ö×Ö·û´æÈëc2
if c2=='*' //Ϊ/**/×¢Ê͵ĿªÍ·
tag = 2
else if c2=='/' //Ϊ//×¢Ê͵ĿªÍ·
tag = 1
else //²»ÊÇ×¢Êͱê¼Ç
½«c1, c2±£´æ
else //¶ÁÈëµÄ×Ö·ûΪ´úÂë
±£´æc1
else if tag==1 //¶ÁÈëµÄÊÇ//×¢ÊÍ
if c1=='\n' //ΪעÊͽáÊø±ê¼Ç
tag=0
else //¶ÁÈëµÄÊÇ/**/×¢ÊÍtag==2
if c1=='*' //¿ÉÄÜΪעÊͽáÊø±ê¼Ç
¶ÁÈëÒ»¸ö×Ö·û¸³¸øc2
if c2=='/' //ÊÇ/**/×¢Êͽáβ
tag=0
else //×¢ÊÍûÓнáÊø
nothing
goto a
³ÌÐòÇåµ¥ÈçÏ£º
//¶ÔÔ´Îļþ½øÐÐɨÃ裬ɾ³ýÆäÖеÄ×¢ÊÍ
#include <stdio.h>
void scan(char *filename)
{
int tag=0;//0:¶ÁÈ¡µÄ×Ö·ûΪ´úÂ룻1:¶ÁÈ¡µÄ×Ö·ûΪ//×¢ÊÍ£»2:¶ÁÈ¡µÄ×Ö·ûΪ/**/×¢ÊÍ
char temp1, temp2;
FILE *in, *out;
in = fopen(filename,"r");
if(in==NULL)
{
printf("cannot open the input file!");
}
out = fopen("out.c", "w");
if(out==NULL)
{
printf("cannot open the output file!");
}
temp1 = fgetc(in);
while(temp1!=EOF)
{
printf("%c", temp1);
if(0==tag)
{
if('/'==temp1)
{
temp2 = fgetc(in);
if('*'==temp2)
{
tag = 2;
}
else if('/'==temp2)
{
tag = 1;
}
else
{
fputc(temp1, out);
fputc(temp2, out);
}
}
else
{
fputc(temp1, out);
}
}
else if(1==tag)
{
if('\n'==temp1)
{
tag = 0;
}
}
else
{
if('*'==temp1)
{
temp2 =
Ïà¹ØÎĵµ£º
ÓÃÁËÈýÖÖ·½·¨...
#if 0
void StringTokenize(const std::string& strSrc, const std::string& strDelimit, std::vector<std::string>& vecSub)
{
if (strSrc.empty() || strDelimit.empty())
{
throw "tokenize: empty string\n";
......
´úÂë+½á¹û£¬²»×ö½âÊÍ
µ±È»£¬¶ÔÓÚpythonûÓÐvirtual functionһ˵£¬¹À¼Æµ±×÷¶Ô±ÈÒ»¸öÀý×Ó¿´¿´°É¡£
#include <iostream>
using namespace std;
class base
{
public:
virtual void foo() { cout << "base" << endl; }
base() { foo() ;}
};
class derive: public base
{
pub ......
Ò»£® ºÎν¿É±ä²ÎÊý
int printf( const char* format, ...);
ÕâÊÇʹÓùýCÓïÑÔµÄÈËËùÔÙÊìϤ²»¹ýµÄprintfº¯ÊýÔÐÍ£¬ËüµÄ²ÎÊýÖоÍÓй̶¨²ÎÊýformatºÍ¿É±ä²ÎÊý£¨Óᱡ¡±±íʾ£©¡£
¶øÎÒÃÇÓÖ¿ÉÒÔÓø÷ÖÖ·½Ê½À´µ÷ÓÃprintf,Èç:
printf("%d",value);
printf("%s",str);
printf("the number is %d ,st ......
1. cÓïÑÔÖеÄÕûÊýÀàÐÍÓÐchar, short, int, longµÈ¼¸ÖÖ, ÏÂÃæÊÇCÓïÑÔ¶ÔÿÖÖÊý¾ÝÀàÐͳ¤¶ÈµÄ¹æ¶¨:
(a). shortºÍlongÀàÐ͵ij¤¶È²»Ïàͬ
(b). intÀàÐÍͨ³£Í¬¾ßÌå»úÆ÷µÄÎïÀí×Ö³¤Ïàͬ
(c). shortͨ³£ÊÇ16bits, intͨ³£ÊÇ16bits or 32bitsÿÖÖ±àÒëÆ÷¿ÉÒÔ¸ù¾ÝÓ²¼þµÄ²»Í¬×ÔÓÉÈ·¶¨, µ«ÊÇshortºÍint±ØÐë×îÉÙÊÇ16bits, ¶ølongÀàÐͱØÐë× ......