You are here


Technical Notes

These notes are my personal online notebook of useful commands and "how-to's". You are welcome to make use of them if you find them helpful. They obviously don't come with any warranty! Click on one of the category tags above for the notes in any category.

Convert Roman numerals to decimal integers in C++

// Converts Roman numerals to decimal integers.
// This code is very resilient to non-standard or variant forms, but does not handle
// exotic forms such as fractions (S etc.), the overstrike x1000 operator or unicode numerals.
// Andrew Fountain, released under GPL 3.0 or higher
#define ID "$Id: roman_num.cpp 46 2012-08-03 18:24:25Z andrewfn $"
#include <iostream>
#include <string.h>
using namespace std;

/* Helper function for romChars()
 * return the value of a Roman character, or zero if not a valid character

C++ string handling

Read a line from a file: ( )

using namespace std;

void main ()
        string STRING;
	ifstream infile; ("names.txt");
        while(!infile.eof) // To get you all the lines.
	        getline(infile,STRING); // Saves the line in STRING.

Alternately we can open the file with: ( )


C++ Sample Code

#include <iostream>
using namespace std;

void f(const char *g);
void f(void);

void f(const char *g) { cout << "Hello, " << g << "!" << endl; }
void f(void) { cout << "Welcome to Paradise!" << endl; }

int main(int argc, char *argv[])
	return 0;

C++ Notes

Subscribe to RSS - C++