Posts

Showing posts from December, 2011

Mapping Words to Line Numbers in Text Files in STL / C++

Image
Following on from the previous post , this example shows an example of how to use an STL multimap to track the line number(s) associated with each word in a text file. This program essentially reads in text line-by-line, while stripping out all occurrences of punctuation and other non-alphanumeric charcters. Each pair is inserted into the multimap container using the insert function. As with the previous posting, which deals with counting the frequency of words in a file, this example also uses the sample Hamlet.txt file . Code listing as follows: [code language="cpp"] #include <iostream> #include <sstream> #include <fstream> #include <map> using namespace std; int main() { const string path = "/home/andy/NetBeansProjects/Hamlet.txt"; //Linux //const string path = "C:\\Dump\\Hamlet.txt"; ifstream input( path.c_str() ); if ( !input ) { cout << "Error opening file." << endl; ...

Counting the Number of Words in a Text File in STL / C++

Image
This post aims to illustrate the power of using STL's associative arrays as a word counter. It reads the entire contents of the text file, word-by-word, and keeps a running total of the number of occurences of each word. All using just a few lines of code, discounting the bits that output the results.

How to Create an Installer with Microsoft Visual Studio

Image
Introduction Visual Studio 2010 contains a package that enables you to create Windows installer files for your applications. Follow these simple steps to build your own setup package for the Visual Studio application you are working on.