首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

C/C++读写资料实例

2012-12-24 
C/C++读写文件实例// OptFile.cpp : 定义控制台应用程序的入口点。//#include stdafx.h#include iostrea

C/C++读写文件实例

// OptFile.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include <iostream>#include <string.h>using namespace std;  //!计算字符串的长度int  myStrlen(const char pStr[]){  for(int i=0;;i++) {  if(pStr[i]=='\0')  {   return i;  } }}//!计算字符串的长度int  myStrlenx(const char* pStr){ const char* pFirst = pStr; while(*pFirst++ != '\0'); return pFirst - pStr -1;}//!执行函数int _tmain(int argc, _TCHAR* argv[]){ char szName[16] = "test123"; char szName2[16] = {'\0'}; strcpy(szName2,szName); cout<<szName2<<endl; //! 如果两个字符串相等,返回0,如果第一个大于第二个返回正数,小于,返回负数 if(strcmp("abd","abc")  > 0) {  cout<<"大于"<<endl; } const char* pStrA = NULL; pStrA = strstr("abcabcabcabcdabc","abcde"); if(pStrA == NULL) {  cout<<"没有找到"<<endl; }else {  cout<<pStrA<<endl; } cout<<myStrlenx(szName2)<<endl; return 0; rename("c:/a/abcabc.txt","c:/a/abc.txt"); return 0; remove("c:/sss.txt"); FILE* pFile = fopen("c:/test.txt","r"); char szBuf[1024]; fgets(szBuf,1024,pFile); cout<<szBuf<<endl; fclose(pFile); pFile = fopen("c:/test.txt","a+"); //! 向文件中写字符串函数 char* pStr = "你好,Game College";  fputs(pStr,pFile); int iAge = 20; char chChar = 's'; fprintf(pFile,   "%s-----%d --%c","网页",iAge,chChar); fclose(pFile); return 0; 
?

热点排行