1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| #include <iostream>
#include <string>
#include <limits>
using namespace std;
const size_t MAX_INPUT_SIZE = 256;
int main( int argc, char* argv[] )
{
int num;
cout << "num: ";
cin >> num;
cout << "num = " << num << endl << "str: ";
cin.clear();
cin.ignore( numeric_limits<streamsize>::max(), '\n' );
char sz[MAX_INPUT_SIZE];
cin.getline( sz, MAX_INPUT_SIZE, '\n' );
string str( sz );
cout << "str = " << str << endl;
cout << "end" << endl;
cin.get();
return 0;
} |