StringExample.cpp 1.63 KB
Newer Older
Nina Džugasová's avatar
Nina Džugasová committed
1
#include <iostream>
2
#include <TNL/String.h>
3
#include <TNL/File.h>
Nina Džugasová's avatar
Nina Džugasová committed
4

5 6
using namespace TNL;
using namespace std;
Jakub Klinkovský's avatar
Jakub Klinkovský committed
7

8
int main( int argc, char* argv[] )
Nina Džugasová's avatar
Nina Džugasová committed
9
{
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
   String emptyString;
   String string1( "string 1" );
   String string2( "string 2" );
   String string3( string2 );
   String string4 = convertToString( 28.4 );

   cout << "empytString = " << emptyString << endl;
   cout << "string1 = " << string1 << endl;
   cout << "string2 = " << string2 << endl;
   cout << "string3 = " << string3 << endl;
   cout << "string4 = " << string4 << endl;

   cout << "emptyString size = " << emptyString.getSize() << endl;
   cout << "string1 size = " << string1.getSize() << endl;
   cout << "string1 length = " << string1.getLength() << endl;

   const char* c_string = string1.getString();
   cout << "c_string = " << c_string << endl;

   cout << " 3rd letter of string1 =" << string1[ 2 ] << endl;

   cout << " string1 + string2 = " << string1 + string2 << endl;
32
   cout << " string1 + \" another string\" = " << string1 + " another string" << endl;
33 34 35 36 37 38 39 40 41 42 43 44 45 46
   
   string2 += "another string";
   cout << " string2 = " << string2;
   string2 = "string 2";

   if( string3 == string2 )
      cout << "string3 == string2" << endl;
   if( string1 != string2 )
      cout << "string1 != string2" << endl;

   if( ! emptyString )
      cout << "emptyString is empty" << endl;
   if( string1 )
      cout << "string1 is not empty" << endl;
47

48
   File myFile;
Jakub Klinkovský's avatar
Jakub Klinkovský committed
49
   myFile.open( "string_save.out", std::ios_base::out );
50 51 52
   myFile << string1;
   myFile.close();

Jakub Klinkovský's avatar
Jakub Klinkovský committed
53
   myFile.open( "string_save.out", std::ios_base::in );
54
   myFile >> string3;
55
   cout << "string 3 after loading = " << string3 << endl;
Nina Džugasová's avatar
Nina Džugasová committed
56
}