-
problems with date entry
Hi everyone this is my first post, please be nice :p :)
so i am writing a paintball booking program as a project i am doing allright but i have to check for invalid date entries in my input by reading the string input into a buffer that will accomodate the largest string size. At the moment the date is input into three seperate char arrays, dd, mm, yyyy. I am stumped as to how i can read the string input into a buffer to check for errors >.< i think i might need to use cin.read() but im not sure how this works and which arguements i should pass, thanks for your help :)
-
It sounds like you are using C style strings. There are functions available to find a character in a string (like '/') or tokenize based on a character. There are also functions to convert to integers so you can validate that the month is between 1 and 12 and stuff like that. I don't think you need cin.read() for that, just cin >> or getline.
The same types of options are available with C++ strings and stringstreams which I find easier deal with and harder to mess up.
-
Try this perhaps,
http://www.daniweb.com/code/snippet367.html
A useful snippet from one of our cprog members, if you might be having trouble handling actual dates.
And I found this useful
http://www.cprogramming.com/tutorial/string.html
Code:
string::iterator my_iter;
for(my_iter = my_string.begin(); my_string != my_string.end(); my_iter++)
{
cout<<*my_iter;
}
If you use the iterator method look out for this little bug btw
Code:
string::iterator my_iter;
for(my_iter = my_string.begin(); my_iter != my_string.end(); my_iter++)
{
cout<<*my_iter;
}
-
thanks for your replies everyone i figured it'd be a simple cin with an array or with loops or something but the instruction is worded like this:
•Check for invalid entries such as the length of the date string.
Note: The string should be read into a buffer that will accommodate the longest string that can be entered at the keyboard.
so i figured it'd be something complicated i guess not :) thanks for help