Hi!
My English grammar is not good. Avoid any grammar mistake.
I am trying to create a program in c++ which will store a message from user and display it latter. But cin.getline() function is refusing to response. I am using dev-c++ 5.11 version of c++ compiler. The source code is;
#include<iostream>
#include<conio.h>
#include<fstream>
using namespace std;
int main()
{
int n,x,j;
char me[255];
ifstream rev;
ofstream store;
cout<<"1:Enter your message\t2: Read your message\n";
cout<<"Enter your choice";
cin>>n;
switch(n)
{
case 1:
cout<<"Enter your message(Max character 253)\n";
cin.getline(me,255);
cout<<"Skiped";
store.open("Message.txt");
store<<me;
store.close();
break;
case 2:
cout<<"Accessing file....";
rev.open("Message.txt");
rev>>me;
cout<<rev;
rev.close();
break;
default:
cout<<"Error";
}
getch();
return 0;
dummy is actually useless and can be deleted.
Basically I have inserted this to get the user choice. choice = getch() - '0';
If you press 1 getch() will return 49 and to get the value 1 you need to subtract 48 which is the same as '0'