I have been tring to create a simple Xml file creator using c++ but i had a problem which is when i am creating a loop with for and put getline(cin,string) the loop ignore it , i have tried to put cin.ignore() but it did not work well and i did not want the out put that i want . please any ideas
the code :
#include<iostream>
#include<fstream>
#include<string>
#define tags 1
using namespace std;
int main()
{
int i;
string tag_name,file_location,file_name,file,tag_content;
double xml_version =1.0;
cout<<"Please Enter the xml file location (example e:\\)";
getline(cin,file_location);
cout<<"Please Enter file name:";
getline(cin,file_name);
file=file_location+file_name+".xml";
cout<<"Enter the xml version:(default 1.0)";
cin>>xml_version;
ofstream fout (file);
fout<<"<?xml version="<<"\""<<xml_version<<"\""<<"?>"<<endl;
for(i=0;i<=tags;i++)
{
cout<<"Enter the Tag No."<<i<<" name :"<<endl;
getline(cin,tag_name);//the compiler skip this line
cout<<"Enter the Tag NO."<<i<<" content :";
getline(cin,tag_content);//the compiler skip this line
if(tag_content.empty())
fout<<"<"<<tag_name<<">"<<"<"<<tag_name<<"\>";
else fout<<"<"<<tag_name<<">"<<tag_content<<"</"<<tag_name<<">"<<endl;
}
cout<<"The xml file available at "<<file<<endl;
}
Aucun commentaire:
Enregistrer un commentaire