Read a string from the keyboard and determines its length - C++ File Stream

C++ examples for File Stream:cin

Description

Read a string from the keyboard and determines its length

Demo Code

#include <iomanip>
#include <iostream>
#include <string>

int main(int argc, const char *argv[]) {
    std::string input;/*from ww w . j a  v  a2 s.  c o  m*/

    std::cout << "Enter a string: ";
    std::getline(std::cin, input);

    int i;
    for (i = 0; input[i] != '\0'; ++i)

    std::cout << "Length of string: " << input << " = " << i << std::endl;

    return 0;
}

Result


Related Tutorials