Proper template design

template<typename T>
inline void doMax(const T& a, const T& b)
{
   f(a > b ? a : b);
}

How do I compile a C++ program under linux?

Make sure to use g++, not gcc.

How to print a class name at runtime

#include <iostream>
#include <typeinfo>
using namespace std;
int main() {
   int i;
   cout << typeid(i).name();
   return 0;
}

Loading a file

std::string getFile(const char *fname)
{
    std::string fileLines;
    std::ifstream infile(fname);
    if (infile.is_open())
    {
        while (!infile.eof())
        {
            std::string curLine;
            std::getline(infile, curLine);
            fileLines += curLine + "\n";
        }
        infile.close();
    }
    return fileLines;
}

Links

-- TWikiGuest - 07 Dec 2001

Topic revision: r4 - 05 Mar 2010 - 20:51:56 - MattWalsh
 
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback