I'm using insert() function to take input in which I'm trying a different methods to take input but it's now working
Here is the full code. Can anyone please help me how to take an input string
#include <iostream>
using namespace std;
class _string{
private:
char *A;
int size;
public:
_string(){
size = 10;
A = new char[size];
}
_string(int sz){
size = sz;
A = new char[size];
}
~_string(){
delete []A;
}
void insert();
void view();
};
void _string::insert(){
cout<<"enter string: ";
cin.getline(A,size);
}
void _string::view(){
puts(A);
}
int main()
{
_string *arr;
int n;
cout<<"Enter the size of string: "; cin>>n;
arr = new _string(n);
arr->insert();
arr->view();
return 0;
}
But when I'm using c function scanf("%s[^\n],A); its working ....
so please tell me how to use fgets(),getline(),cin.get() in my code