• vcf文件分解


    上上周把手机丢了,可是原先备份的通讯录只有一个.vcf文件,里面含盖了我所有的联系人信息比如100个联系人信息他全存进一个.vcf文件了。换了新手机,怎么也导不到新手机里面,原因是新手机只支持一个.vcf文件里存一条通讯录的那种格式,比如100个联系人信息就得有100个.vcf文件放到内存卡里才能还原。

    我用文本方式观察了一下,正好可以用c++处理一下,正好也练一个文件处理方面的基本功。代码如下,vc6.0编译。

    #include <iostream>
    #include <fstream>
    #include <string>
    
    using namespace std;
    
    int main()
    {
    	ifstream first("D:\\myPro\\phoneBook\\a.vcf",ios::in);//读取的方式打开文件
    
    
    	
    	if(first)
    		cout<<"文件打开成功"<<endl;
    	else
    		cout<<"文件打开失败"<<endl;
    	
    	string result;
    	string temp;
    	string name;
    	
    	
    	while(!first.eof())
    	{
    		char buf[100];
    		first.get(buf,100,'\n');  //读取一行到buf
    		
    		
    		temp=buf;
    		result+=temp+"\n";
    		if(temp.find("N:")!=string::npos&&temp.find("BEGIN")==string::npos&&temp.find("FN")==string::npos&&temp.find("VERSION:")==string::npos)
    		{
    			name.assign(temp,2,temp.length()-2);
    		}
    		
    		if(temp.find("END")!=string::npos)
    		{
    			cout<<"记录为\n"<<result<<endl;
    			cout<<"---------------------------------\n";
    			name=name+".vcf";
    			const char *str=name.c_str();
    			
    			ofstream second(str);//以人物姓名创建一个文件
    			second<<result;
    			second.close();
    			
    			result="";
    			name="";
    		}
    		memset(buf,0,sizeof(buf));
    		first.seekg(2,ios::cur);
    
    	}
    	
    	return 0;
    }
    

    1

    2

    本人新博客网址为:http://www.hizds.com
    本博客注有“转”字样的为转载文章,其余为本人原创文章,转载请务必注明出处或保存此段。c++/lua/windows逆向交流群:69148232
  • 相关阅读:
    uva 442 Matrix Chain Multiplication
    结对编程项目之队友代码分析
    [转] 为什么要使用NoSQL
    Compare Linq2Sql with NHibernate
    使用linq2sql 的DetailView 如何保存多对多关系
    工作流入门
    XML字段的用处
    DesignTimeResourceProviderFactory 不给力啊
    如何给XMLDatasource做分页和排序
    ORM的烦恼
  • 原文地址:https://www.cnblogs.com/zhangdongsheng/p/2128832.html
Copyright © 2020-2023  润新知