0
Can anyone please tell me the syntax of accepting line ( string ) as an input in c++ along with header file required for it ?
5 Respostas
+ 11
int count = 0;
for(int i = 0; i < line.size(); i++) {
if(line[i] == 'k') {
count++;
}
}
cout << count << endl;
+ 9
cout << line << endl;
//For outputting the line
+ 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.
0
thanks sir ...
and what is the syntax of function for showing output of line
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 ?