How do I error check if the user is inputting letters and not numbers?
For example, if the user inputs "Lab.txt" I need to display an error message.
If they input "Lab2part2.txt" then this is correct and what I want.
I've found a lot of information online on how to error check for numbers or a single letter (EX: 1,2,3, etc. or 'A' 'B' 'C') but nothing for actual WORDS or maybe I should refer to it as a string of characters?
Is there any way to do this? Because my program requires I ask the user to input the name of the file. But the way my code is currently set up is even when the user inputs the wrong file name it still opens the file. I want to prevent this from happening so my thought was to error check user input.
Suggestions?
EDIT: This program is not complete. I am in the process of going through and completing each separate function. Before moving on to the next function I need to make sure this one is working properly.
In C++, you can use an std::string for this purpose.
1 2 3
std::string word, line;
std::cin >> word; //using this gets one word from the input
std::getline(std::cin, line); //using this function gets a whole line from the input
Just note that using operator >> can leave extra junk in the input buffer, so be careful about using it and getline() together.