Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use Substr

Status
Not open for further replies.

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.
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top