Aug 2, 2003 #1 DerPflug Programmer Mar 28, 2002 153 US I have a string class variable that I want to check for a certain character: string Date("08/02/2003" How do I determine that the 3rd character in the string is a "/" using the substr method? Also, how do you use c_str? Thanks in advance.
I have a string class variable that I want to check for a certain character: string Date("08/02/2003" How do I determine that the 3rd character in the string is a "/" using the substr method? Also, how do you use c_str? Thanks in advance.
Aug 2, 2003 #2 palbano Programmer Oct 9, 1998 4,341 US substr is used to obtain a copy of a portion of a string not to compare a single character to a value. To perform your compare: Code: string s("08/20/2003"); cout << (s[2] == '/') << endl; cout << s.c_str() << endl; exit(0); -pete Upvote 0 Downvote
substr is used to obtain a copy of a portion of a string not to compare a single character to a value. To perform your compare: Code: string s("08/20/2003"); cout << (s[2] == '/') << endl; cout << s.c_str() << endl; exit(0); -pete