31
|
1 |
|
|
2 |
// STLport regression testsuite component.
|
|
3 |
// To compile as a separate example, please #define MAIN.
|
|
4 |
|
|
5 |
#include <string>
|
|
6 |
#include <iostream>
|
|
7 |
|
|
8 |
#ifdef MAIN
|
|
9 |
#define string1_test main
|
|
10 |
#endif
|
|
11 |
|
|
12 |
#if !defined (STLPORT) || defined(__STL_USE_NAMESPACES)
|
|
13 |
using namespace std;
|
|
14 |
#endif
|
|
15 |
int string1_test(int, char**)
|
|
16 |
{
|
|
17 |
int failures=0;
|
|
18 |
cout<<"Results of string1_test:"<<endl;
|
|
19 |
char* array = "Hello, World!";
|
|
20 |
std::string v(array);
|
|
21 |
int i;
|
|
22 |
cout << v << endl;
|
|
23 |
|
|
24 |
if(v.compare("Hello, World!"))
|
|
25 |
failures++;
|
|
26 |
|
|
27 |
v.erase(v.begin() + 1, v.end() - 1); // Erase all but first and last.
|
|
28 |
for(i = 0; i < v.size(); i++)
|
|
29 |
cout << "v[" << i << "] = " << v[i] << endl;
|
|
30 |
cout << endl;
|
|
31 |
|
|
32 |
if('H'!=v[0])
|
|
33 |
failures++;
|
|
34 |
else if('!'!=v[1])
|
|
35 |
failures++;
|
|
36 |
|
|
37 |
|
|
38 |
v.insert(1, (char*)array);
|
|
39 |
v.erase(v.begin()); // Erase first element.
|
|
40 |
v.erase(v.end() - 1); // Erase last element.
|
|
41 |
cout << v << endl;
|
|
42 |
if(v.compare("Hello, World!"))
|
|
43 |
failures++;
|
|
44 |
v.clear(); // Erase all.
|
|
45 |
|
|
46 |
if(failures)
|
|
47 |
return 1;
|
|
48 |
else
|
|
49 |
return 0;
|
|
50 |
}
|
|
51 |
|
|
52 |
|