weiler atherton polygon clipping source code in c code example

Example 1: tellg and seekg c++

// read a file into memory
#include <iostream>     // std::cout
#include <fstream>      // std::ifstream

int main () {
  std::ifstream is ("test.txt", std::ifstream::binary);
  if (is) {
    // get length of file:
    is.seekg (0, is.end);
    int length = is.tellg();
    is.seekg (0, is.beg);

    // allocate memory:
    char * buffer = new char [length];

    // read data as a block:
    is.read (buffer,length);

    is.close();

    // print content:
    std::cout.write (buffer,length);

    delete[] buffer;
  }

  return 0;
}

Example 2: floor() in c++

floor(x):This function in C++ returns the smallest possible integer value which is smaller
 than or equal to the given argument.
Input : 2.5 ,-2.1 ,2.9
Output : 2 ,-3, 2

Example 3: fail() in c++

#include <iostream>
using namespace std;

int main()
{
    int number;
    do{
        cin >> number;
        if(cin.fail())
            cout << "Not a number " << endl;
    }while(!cin.fail());
    cout << "number is " << number << endl;
    system("pause");
    return 0;
}

Tags:

Java Example