Rozdíly

Zde můžete vidět rozdíly mezi vybranou verzí a aktuální verzí dané stránky.

Odkaz na výstup diff

Obě strany předchozí revize Předchozí verze
Následující verze
Předchozí verze
public:pb161:stringmain_test [2011/01/13 12:53]
Petr Svenda
public:pb161:stringmain_test [2018/02/24 19:10] (aktuální)
Řádek 1: Řádek 1:
 +<code c stringmain.cc>​
 +#include "​stringint.h"​
 +#include <​iostream>​
 +#include <​sstream>​
 +#include <​climits>​
 +using namespace std;
  
 +int main()
 +{
 + cout << "-- Zakladni testy : stream input --" << endl;
 +
 + stringstream s;
 + s << ULONG_MAX << " " << LONG_MAX << " " << LONG_MIN << endl;
 +
 + stringint x;
 +
 + s >> x;
 + cout << "Ma vypsat \""​ << ULONG_MAX << "​\""​ << endl;
 + cout << " ​          "​ << x << endl;
 +
 + s >> x;
 + cout << "Ma vypsat \""​ << LONG_MAX << "​\""​ << endl;
 + cout << " ​          "​ << x << endl;
 +
 + s >> x;
 + cout << "Ma vypsat \""​ << LONG_MIN << "​\""​ << endl;
 + cout << " ​          "​ << x << endl;
 +
 + s.str("​123456789123456789123456789123456789"​);​
 + s >> x;
 + cout << "Ma vypsat \""​ << "​123456789123456789123456789123456789"​ << "​\""​ << endl;
 + cout << " ​          "​ << x << endl;
 +
 + s.str("​++"​);​
 + s.clear();
 + s >> x;
 + cout << "Ma vypsat \""​ << "​0"​ << "​\""​ << endl;
 + cout << " ​          "​ << x << endl;
 +
 + s.str("​+"​);​
 + s.clear();
 + s >> x;
 + cout << "Ma vypsat \""​ << "​0"​ << "​\""​ << endl;
 + cout << " ​          "​ << x << endl;
 +
 +
 + cout << endl << "-- Zakladni testy : long a unsigned long kostruktory --" << endl;
 +
 + stringint y1(LONG_MAX);​
 + stringint y2(LONG_MIN);​
 + stringint y3(ULONG_MAX);​
 +
 + cout << "Ma vypsat \""​ << LONG_MAX << "​\""​ << endl;
 + cout << " ​          "​ << y1 << endl;
 +
 + cout << "Ma vypsat \""​ << LONG_MIN << "​\""​ << endl;
 + cout << " ​          "​ << y2 << endl;
 +
 + cout << "Ma vypsat \""​ << ULONG_MAX << "​\""​ << endl;
 + cout << " ​          "<<​ y3 << endl;
 +
 + cout << endl << "-- Operator plus --" << endl;
 +
 + s.str("​9999999999999999999999999999999999 1");
 + s.clear();
 + stringint z1,z2;
 + s >> z1 >> z2;
 + cout << "Ma vypsat \""​ << "​10000000000000000000000000000000000"​ << "​\""​ << endl;
 + cout << " ​          "​ << (z1+z2) << endl;
 +
 + s.str("​9999999999999999999999999999999999 -9999999999999999999999999999999999"​);​
 + s.clear();
 + s >> z1 >> z2;
 + cout << "Ma vypsat \""​ << "​0"​ << "​\""​ << endl;
 + cout << " ​          "​ << (z1+z2) << endl;
 +
 + s.str("​-9999999999999999999999999999999999 9999999999999999999999999999999999"​);​
 + s.clear();
 + s >> z1 >> z2;
 + cout << "Ma vypsat \""​ << "​0"​ << "​\""​ << endl;
 + cout << " ​          "​ << (z1+z2) << endl;
 +
 + s.str("​-1 -9999999999999999999999999999999999"​);​
 + s.clear();
 + s >> z1 >> z2;
 + cout << "Ma vypsat \""​ << "​-10000000000000000000000000000000000"​ << "​\""​ << endl;
 + cout << " ​          "​ << (z1+z2) << endl;
 +
 + cout << endl << "-- Operator minus --" << endl;
 +
 + s.str("​9999999999999999999999999999999999 -1");
 + s.clear();
 + s >> z1 >> z2;
 + cout << "Ma vypsat \""​ << "​10000000000000000000000000000000000"​ << "​\""​ << endl;
 + cout << " ​          "​ << (z1-z2) << endl;
 +
 + s.str("​9999999999999999999999999999999999 9999999999999999999999999999999999"​);​
 + s.clear();
 + s >> z1 >> z2;
 + cout << "Ma vypsat \""​ << "​0"​ << "​\""​ << endl;
 + cout << " ​          "​ << (z1-z2) << endl;
 +
 + s.str("​-9999999999999999999999999999999999 -9999999999999999999999999999999999"​);​
 + s.clear();
 + s >> z1 >> z2;
 + cout << "Ma vypsat \""​ << "​0"​ << "​\""​ << endl;
 + cout << " ​          "​ << (z1-z2) << endl;
 +
 + s.str("​-1 9999999999999999999999999999999999"​);​
 + s.clear();
 + s >> z1 >> z2;
 + cout << "Ma vypsat \""​ << "​-10000000000000000000000000000000000"​ << "​\""​ << endl;
 + cout << " ​          "​ << (z1-z2) << endl;
 +
 + cout << endl << "-- Operator nasobeni --" << endl;
 + s.str("​9999999999999999999999999999999999 123456790"​);​
 + s.clear();
 + s >> z1 >> z2;
 + cout << "Ma vypsat \""​ << "​1234567899999999999999999999999999876543210"​ << "​\""​ << endl;
 + cout << " ​          "​ << (z1*z2) << endl;
 +
 + s.str("​9999999999999999999999999999999999 -123456790"​);​
 + s.clear();
 + s >> z1 >> z2;
 + cout << "Ma vypsat \""​ << "​-1234567899999999999999999999999999876543210"​ << "​\""​ << endl;
 + cout << " ​          "​ << (z1*z2) << endl;
 +
 + s.str("​-9999999999999999999999999999999999 -123456790"​);​
 + s.clear();
 + s >> z1 >> z2;
 + cout << "Ma vypsat \""​ << "​1234567899999999999999999999999999876543210"​ << "​\""​ << endl;
 + cout << " ​          "​ << (z1*z2) << endl;
 +
 + s.str("​9999999999999999999999999999999999 0");
 + s.clear();
 + s >> z1 >> z2;
 + cout << "Ma vypsat \""​ << "​0"​ << "​\""​ << endl;
 + cout << " ​          "​ << (z1*z2) << endl;
 +
 + cout << endl << "-- Operator deleni --" << endl;
 + s.str("​9999999999999999999999999999999999 123456790"​);​
 + s.clear();
 + s >> z1 >> z2;
 + cout << "Ma vypsat \""​ << "​81000000081000000081000000"​ << "​\""​ << endl;
 + cout << " ​          "​ << (z1/z2) << endl;
 +
 + s.str("​9999999999999999999999999999999999 -123456790"​);​
 + s.clear();
 + s >> z1 >> z2;
 + cout << "Ma vypsat \""​ << "​-81000000081000000081000000"​ << "​\""​ << endl;
 + cout << " ​          "​ << (z1/z2) << endl;
 +
 + s.str("​-9999999999999999999999999999999999 -123456790"​);​
 + s.clear();
 + s >> z1 >> z2;
 + cout << "Ma vypsat \""​ << "​81000000081000000081000000"​ << "​\""​ << endl;
 + cout << " ​          "​ << (z1/z2) << endl;
 +
 + s.str("​9999999999999999999999999999999999 0");
 + s.clear();
 + s >> z1 >> z2;
 + cout << "Ma vypsat \""​ << "​0"​ << "​\""​ << endl;
 + cout << " ​          "​ << (z1/z2) << endl;
 +
 + cout << endl << "-- Operator modulo --" << endl;
 + s.str("​9999999999999999999999999999999999 123456790"​);​
 + s.clear();
 + s >> z1 >> z2;
 + cout << "Ma vypsat \""​ << "​9999999"​ << "​\""​ << endl;
 + cout << " ​          "​ << (z1%z2) << endl;
 +
 + s.str("​9999999999999999999999999999999999 9999999999999999999999999999999999"​);​
 + s.clear();
 + s >> z1 >> z2;
 + cout << "Ma vypsat \""​ << "​0"​ << "​\""​ << endl;
 + cout << " ​          "​ << (z1%z2) << endl;
 +
 + cout << endl << "-- Operator umocneni --" << endl;
 + s.str("​9999999999999999999999999999999999 0");
 + s.clear();
 + s >> z1 >> z2;
 + cout << "Ma vypsat \""​ << "​1"​ << "​\""​ << endl;
 + cout << " ​          "​ << (z1^z2) << endl;
 +
 + s.str("​999 23");
 + s.clear();
 + s >> z1 >> z2;
 + cout << "Ma vypsat \""​ << "​977251237821451702332497952715272934750699931056086640146770747022999"​ << "​\""​ << endl;
 + cout << " ​          "​ << (z1^z2) << endl;
 +
 + cout << endl << "-- Operator odmocneni --" << endl;
 + s.str("​9999999999999999999999999999999999"​);​
 + s.clear();
 + s >> z1;
 + cout << "Ma vypsat \""​ << "​99999999999999999"​ << "​\""​ << endl;
 + cout << " ​          "​ << (~z1) << endl;
 +
 + cout << endl << "-- Operator negace --" << endl;
 + s.str("​9999999999999999999999999999999999"​);​
 + s.clear();
 + s >> z1;
 + cout << "Ma vypsat \""​ << "​-9999999999999999999999999999999999"​ << "​\""​ << endl;
 + cout << " ​          "​ << (-z1) << endl;
 +
 + return 0;
 +}
 +</​code>​
QR Code
QR Code public:pb161:stringmain_test (generated for current page)