#include<iostream> #include<stdlib.h> #include<string.h> #include<fstream> using namespace std; class item{ char name[10],name2[10],name1[10]; public: void set_item(char *n,char *n1,char *n2){ strcpy(name,n); strcpy(name1,n1); strcpy(name2,n2); } void get_item(){ cout<<name; cout<<name1; cout<<name2; } }; int main(){ item obj; ofstream out("a.txt"); char name[10],name1[10],name2[10]; string l; cout<<"Enter a item :"; cin>>name; cout<<"Enter a second item :"; cin>>name1; cout<<"Enter a third item :"; cin>>name2; obj.set_item(name,name1,name2); out<<name; out<<"\n"<<name1; out<<"\n"<<name2; out.close(); ifstream in("a.txt"); while(in){ getline(in,l); cout<<"\n"<<l; } }
Enter first item AC Enter second item TV Enter third item BAG AV TV BAG
If you like code with vibhu and would like to contribute, you can also write an article using This link :
https://docs.google.com/forms/d/e/1FAIpQLScAmvlPvNUz35R-G0nc_zpRVP3o8xlhtFgC3aKPyLetX_RyXg/viewform?pli=1
OR mail your article to codewithvibhu@gmail.com. See your article appearing on the code with vibhu main page and help other students.
0 Comments