Read a string into character array variable state - C++ File Stream

C++ examples for File Stream:cin

Description

Read a string into character array variable state

Demo Code

#include <iomanip>
#include <iostream>
#include <limits>
using namespace std;
int main(int argc, const char *argv[]) {

    char state[11];
    std::cout << "Enter a 10 char string: ";

    std::cin.get(state, 11);/*from   w w w. jav  a  2  s.  c  o  m*/
    std::cin.clear();
    std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');

    std::cout << state << std::endl;

    return 0;
}

Result


Related Tutorials