0

Can anyone please tell me the syntax of accepting line ( string ) as an input in c++ along with header file required for it ?

4th Dec 2017, 4:14 PM
Bhushan Thakre
Bhushan Thakre - avatar
5 Respostas
+ 11
int count = 0; for(int i = 0; i < line.size(); i++) { if(line[i] == 'k') { count++; } } cout << count << endl;
4th Dec 2017, 5:13 PM
Cool Codin
Cool Codin - avatar
+ 9
cout << line << endl; //For outputting the line
4th Dec 2017, 5:02 PM
Cool Codin
Cool Codin - avatar
+ 3
It's not necessary, but go ahead and #include <string>, then: string line; getline(cin, line); This will accept white space as well, so you can enter multiple words.
4th Dec 2017, 4:36 PM
Zeke Williams
Zeke Williams - avatar
0
thanks sir ... and what is the syntax of function for showing output of line
4th Dec 2017, 4:40 PM
Bhushan Thakre
Bhushan Thakre - avatar
0
thanks for clearing my doubt sir... I have one more doubt , please try to answer this I want to count how many 'k' are there in that line ... what will be the syntax for that ?
4th Dec 2017, 5:07 PM
Bhushan Thakre
Bhushan Thakre - avatar