C++ examples for File Stream:cin
Read a string from the keyboard and determines its length
#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; }