I am learning c++ by myself. I just try to do a library program. But something is wrong. after the user select number from menu, program turns off. Here is my code:
Here is my menu.cpp:
using namespace std;
class Menu{
public:
int menuchoice();
};
int Menu::menuchoice()
{
int choice;
cout<<"1 - Kitaplarim"<<endl;
cout<<"2 - Kitap Ekle"<<endl;
cout<<"3 - About coder"<<endl;
cout<<"4 - Exit"<<endl;
cout<<"Bir secenek secin";
cin>>choice;
return choice;
}
Here is my main.cpp
#include<iostream>
#include<conio.h>
#include<fstream>
#include<iomanip>
#include<string>
#include "menu.cpp"
using namespace std;
class Kitap{
public:
string Ad;
void takeinfobook();
};
void Kitap::takeinfobook(){
cout<<"Kitabin adi...:";
std::getline(std::cin, Ad);
ofstream savefile("savebook.txt");
savefile<<Ad;
cout<<Ad;
}
main(){
Menu menu;
int choice = menu.menuchoice();
if(choice==2)
{
Kitap book;
book.takeinfobook();// After this line program must take me a book name and write to file. But it doesnt. Program turns off..
}
else
{
cout<<"hodor";
}
}