counting using can.get(ch)

What is the output of the following code fragment?
(Assume all headers files are included)
int num=0;
char ch;
while(cin.get(ch)!= "\0")
num++;
cout<<num;

If the input contains: Do you like C++.

a) 13
b) 14
c) 15
d) 16
Answer: 15
1
2
3
4
5
6
7
8
9
10
#include<iostream>
#include<string>

int main(){

std::cout<<"Enter your text: "<<std::endl;
std::string text;
getline(std::cin,text);
std::cout<<"Text length is "<<text.length()<<std::endl;
}
Topic archived. No new replies allowed.