@Ajitverma1503
String can work with other data types and we use it very often with other data types.
The problem with your code is not actually with int or any other data type but rather with the input.
getline( ) is the actual problem.
There are several ways to take input for strings , each having its own perks and drawbacks. The problem with getline( ) is that it causes several problems with buffer.
I suggest you to remove the getline( ) statement for once and use
cin >> c;
in place of it and you will find that your problem is solved.
Using cin will only allow you to take a single word as input though , as I said , each method has its own perks and drawbacks.
If you wish to take input till new line character ( as I can guess that this was the reason why you used getline( ) in the first place ) , you need to clear the buffer first.
Write
cin.ignore( );
before getline(cin,c) ; statement.
cin.ignore( ); commands the compiler to empty the buffer so that we can get proper input using getline( ).
Try these variations and let me know if you have any further doubts.