Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

c/vc++ »·¾³Ï²»Í¬µÄÎļþ³¤¶È»ñÈ¡·½·¨

£¨Ò»£©
¶ÔÎļþ²Ù×÷ʱÓÐʱ»ñµÃÎļþµÄ´óСʱ±ØÒªµÄ.ÏÂÃæÊÇ»ñµÃÆä´óССµÄ½Ï¼òµ¥·½·¨.
#include<io.h>   //CÓïÑÔÍ·Îļþ
#include<iostream>   //for system();
using namespace std;
int main()
{
  int handle;
  handle = open("test.txt", 0x0100); //open file for read
  long length = filelength(handle); //get length of file
  cout<<"file length in bytes:"<<length<<endl;
  close(handle);
 
  system("pause");
  return 0;
}
£¨¶þ£©
//ÓÃWindows API ÖÐµÄ GetFileSize()»ñµÃÎļþ³¤¶È
//¼ÙÉèÎļþfile.txt ÔÚµ±Ç°Ä¿Â¼ÏÂ
//file.txtµÄÄÚÈÝΪ:123abc
//¹ØÓÚwindows APIº¯ÊýÇé²Î¿¼²¿·Öwindows APIº¯Êý»òMSDN
#include <iostream>
#include <windows.h>   //for windows api
using namespace std;
int main()
{
  //ÓÃAPIº¯ÊýCreateFile()´´½¨Îļþ¾ä±ú
  HANDLE fhadle = CreateFile("file.txt",           //ÎļþÃû»ò·¾¶
                                  0,
                                  0,
                                  0,
                                  OPEN_EXISTING, //Îļþ´æÔÚÔò´ò¿ª²¢¶ÁÈ¡
                              


Ïà¹ØÎĵµ£º

C/C++ÓïÑÔÖÐStaticµÄ×÷ÓÃÏêÊö

ÔÚCÓïÑÔÖУ¬staticµÄ×ÖÃæÒâ˼ºÜÈÝÒ×°ÑÎÒÃǵ¼ÈëÆç;£¬ÆäʵËüµÄ×÷ÓÃÓÐÈýÌõ¡£
£¨1£©ÏÈÀ´½éÉÜËüµÄµÚÒ»ÌõÒ²ÊÇ×îÖØÒªµÄÒ»Ìõ£ºÒþ²Ø¡£
µ±ÎÒÃÇͬʱ±àÒë¶à¸öÎļþʱ£¬ËùÓÐδ¼Óstaticǰ׺µÄÈ«¾Ö±äÁ¿ºÍº¯Êý¶¼¾ßÓÐÈ«¾Ö¿É¼ûÐÔ¡£ÎªÀí½âÕâ¾ä»°£¬ÎÒ¾ÙÀýÀ´ËµÃ÷¡£ÎÒÃÇҪͬʱ±àÒëÁ½¸öÔ´Îļþ£¬Ò»¸öÊÇa.c£¬ÁíÒ»¸öÊÇmain.c¡£
ÏÂÃæÊÇa.cµÄÄÚÈÝ
ch ......

extern "C"

      ΪʲôÐèҪʹÓÃextern "C"ÄØ£¿C++Ö®¸¸ÔÚÉè¼ÆC++֮ʱ£¬¿¼Âǵ½µ±Ê±ÒѾ­´æÔÚÁË´óÁ¿µÄC´úÂ룬ΪÁËÖ§³ÖÔ­À´µÄC´úÂëºÍÒѾ­Ð´ºÃC¿â£¬ÐèÒªÔÚC++Öо¡¿ÉÄܵÄÖ§³ÖC£¬¶øextern "C"¾ÍÊÇÆäÖеÄÒ»¸ö²ßÂÔ¡£
¡¡¡¡ÊÔÏëÕâÑùµÄÇé¿ö:Ò»¸ö¿âÎļþÒѾ­ÓÃCдºÃÁ˶øÇÒÔËÐеúÜÁ¼ºÃ£¬Õâ¸öʱºòÎÒÃÇÐèҪʹÓÃÕâ¸ö¿âÎļþ£ ......

C/C++ µÄÈ«¾Ö±äÁ¿³õʼ»¯Óë²»³õʼ»¯µÄÇø±ð

ÔÚCÓïÑÔÀȫ¾Ö±äÁ¿Èç¹û²»³õʼ»¯µÄ»°£¬Ä¬ÈÏΪ0£¬Ò²¾ÍÊÇ˵ÔÚÈ«¾Ö¿Õ¼äÀ
int x =0; ¸ú int x; µÄЧ¹û¿´ÆðÀ´ÊÇÒ»ÑùµÄ¡£µ«ÆäʵÕâÀïÃæµÄ²î±ðºÜ´ó£¬Ç¿ÁÒ½¨Òé´ó¼ÒËùÓеÄÈ«¾Ö±äÁ¿¶¼Òª³õʼ»¯£¬ËûÃǵÄÖ÷Òª²î±ðÈçÏ£º
±àÒëÆ÷ÔÚ±àÒëµÄʱºòÕë¶ÔÕâÁ½ÖÖÇé¿ö»á²úÉúÁ½ÖÖ·ûºÅ·ÅÔÚÄ¿±êÎļþµÄ·ûºÅ±íÖУ¬¶ÔÓÚ³õʼ»¯µÄ£¬½ÐÇ¿·ûºÅ£¬Î´³õʼ»¯µÄ ......

ΪʲôCºÍC++Å£È˶à

1¡¢CºÍC++¹»±¿£¬±ÆµÄ³ÌÐòÔ±×Ô¼º×öºÜ¶àÊ¡£
CÆäʵ´ó¼Ò¶¼ÖªµÀ£¬ÊÇÒ»ÃÅÖеͼ¶ÓïÑÔ£¬±£ÁôÁËÖ¸ÕëµÈ»ã±àÌØÕ÷£¬Óëϵͳµ×²ã½áºÏÃÜÇС£C++ÄØ£¬¸ü¶àµÄÏò¸öObject C£¬¼´ÃæÏò¶ÔÏóµÄC¡£µ«ÕâЩ£¬Æäʵ²¢²»Äܹ»ÈóÌÐòÔ±ÏԵúÜÅ£¡£
ÎÒ¸öÈ˵ÄÀí½â£¬Ö®ËùÒÔCºÍC++³ÌÐòÔ±ÏԵúÜÅ££¬ÆäʵԭÒòºÍ´ó¼ÒÏëÏñµÄÕýºÃÏà·´£¬²»ÊÇÒòΪCºÍC++̫ǿ´ó£¬¶øÊÇÕâ ......

cʵÏֵĶÁ´óÎļþ·½·¨£¨Ô´´úÂ룩


static char *file2memory(FILE *file, long *size)
{
  char buffer[1024];
  char *string=NULL;
  char *newstring=NULL;
  long len=0;
  long stringlen=0;
  if(file) {
    while((len = fread(buffer, 1, sizeof(buffer), f ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ