Congratulations Sleazy!
Now that we're on the topic however, I just made this one:
#include <iostream>
#include <string>
using namespace std;
// Example of using the generic algos of find and replace
bool
replace ( string &s, const char * find_str, const char * rep_str )
{
unsigned int i = 0;
if (( i=s.find(find_str)) != s.npos)
{
s.replace(i, strlen(find_str), rep_str);
return (true);
}
return(false);
}
void
String_Test ( void )
{
// Create instance of a string from literal string
string s = "Hello World";
// Output of the string in various ways
cout << "s.c_str() = " << s.c_str() << endl;
cout << "s.data() = " << s.data() << endl;
cout << "s = " << s << endl;
cout << "sizeof(s) = " << sizeof(s) << endl;
cout << "s.size = " << s.size() << endl;
cout << "s.length = " << s.length() << endl;
cout << "s.capacity = " << s.capacity() << endl;
cout << "s.max_size = " << s.max_size() << endl;
// output by single char
int len = s.length();
cout << "s[0]-s[" << len << "] = ";
for ( int i=0; i<len; i++ )
{
cout << s[i];
}
cout << endl;
// Creating a string
string s2;
// assignment to a string
s2 = "Hello Mars and Venus";
// concatenate strings together
string s3;
s3 = s + " " + s2;
cout << s3 << endl;
// test for empty string
cout << "s.empty() << " << s.empty() << endl;
//create and empty string
string s4;
cout << "s4.empty() << " << s4.empty() << endl;
//Inline replacement in the string, found
string s5 = "Address: ADD_DATA";
cout << "s5 = " << s5 << endl;
if ( replace(s5, "ADD_DATA", "212 Oak Lane") )
{
cout << "s5 = " << s5 << endl;
}
//Inline replacement in the string, not found
string s6 = "Address: ADD_DATA";
cout << "s6 = " << s6 << endl;
if ( replace(s6, "XYZ", "212 Oak Lane") )
{
cout << "s6 = " << s6 << endl;
}
else
{
cout << "s6 = " << "Not Found" << endl;
}
if ( s5 == s6 )
{
cout << "s5 == s6 = true" << endl;
}
else
{
cout << "s5 == s6 = false" << endl;
}
string s7 = "Test";
string s8 = "test";
if ( s7 < s8 )
{
cout << "Test < test= true" << endl;
}
else
{
cout << "Test < test= false" << endl;
}
}
int
main ( void )
{
String_Test();
return(0);
}
It's not done, and there are some errors. :o