#include <iostream>
//在D盘根目录下分别建立a.txt b.txt
//将excel表格中的姓名和数字分别拷贝入a.txt中
#include <string>
#include <fstream>
using namespace std;
int main(int argc, char** argv)
{
ifstream in,inf("D:\\a.txt");
ofstream out("D:\\b.txt");
string filename;
string line;
string str;
int count , numberLine , unm= 0 ;
out << "var member = [ " <<endl <<" {"<<endl; // 输入到2.txt中
while (in >> str) {
numberLine ++;
}
while (inf >> str) //空格和换行符为分界线 getline (in, line) 换行符为分界线
{
cout << str << endl;
unm ++;
if (count == 0){
out << " \"phone\": \"" <<str << "\","<< endl;
count =1 ;
continue;
}
else{
out << " \"name\": \"" <<str << '\"'<< endl << " }";
if(unm < numberLine )out<<"," << endl<<" {"<<endl;
count = 0 ;
continue;
}
}
out <<endl <<"]"<<endl;
in.close();
//out.close;
return 0;
}