Use
cin.get(letter);to read characters from keyboard. This way you can read all types of characters including space and return characters. After entering a series of characters, press enter so that the last character entered is a return character, you can use it as the terminator of your input. For example, you can use a loop control like
while(letter != '\n')to read all characters until a return key is pressed. To check if a character is uppercase, lower case, or digit, use the integer coding values of ASCII character set. For example, to check if a character is a uppercase letter, use
if(letter >='A' && letter <= 'Z')
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
char data;
//Read the first data item from keyboard
cin.get(data);
//Keep reading until a Ctr Z character is reached
while(data != '\n')
//while(cin)
{
cout << data << endl;
cin.get(data);
}
cout << "Well done!" << endl;
return 0;
}
//int main()
//{
// int data;
// int sum = 0;
//
// //Read the first data item from keyboard
// cin >> data;
//
// //Keep reading until a Ctr Z character is reached
// while(cin)
// {
// sum = sum + data;
// cin >> data;
// }
//
// cout << "The sum of the data items is " << sum << endl;
//
// return 0;
//}
//int main()
//{
// int data;
// int sum = 0;
//
// ifstream inData;
// inData.open("inputData.txt");
//
// //Read the first data item from the file
// inData >> data;
//
// //Keep reading until EOF (end of file) character is reached
// while(inData)
// {
// sum = sum + data;
// inData >> data;
// }
//
// cout << "The sum of the data items in the file is " << sum << endl;
//
// return 0;
//}
inputData.txt
10 5 2 3 4 6