My first cpp program to work on text.
-
In this web site many script are shown. From unix administration to utilities,
which help simulation and compilation automation and others. Most of them are
accessed from:
scripts.
Some of the scripts are specially suited to be called and run from within
vim, as in the following example:
Run a perl script from vim on a block of text, to find N strings in consecutive lines.
The complexity of the scripts was a main consideration in selecting the
script language: simple ones use bash, more text manipulation or hash
kind data base use
perl. Recently some scripts, at work, get more complex and c++ text manipulation
plus object oriented features can reduce significantly the debug time.
-
After reading some good tutorials, I decided to do some simple exercises
to begin with the study.
The
first
ones uses a list to hold some strings which are searched in a file,
if a line contains any of the strings, it will be printed.
The
second
c++ examples reads a ini file with the following
format address/data. It extracts the address and prints it.
The
third
exercise is about regular expression. I have tried multiple times to get
regex to work, on my debian machine at home and failed. Therefor I
decided to do it by executing
from c++ a sed command.
At work, boost library, is installed. With this library, I was finally
able to get regex to work well.
Example c like regular expression,
Example with boolean result,
Example with string replace.
The
forth
exercise is about a simple hash, with a string as the key to the hash.
The
fifth
presents a program to check parenthesis validity in a c, cpp, perl etc...
The
sixth
is a simple example using a double ended queue (deque).
The
seventh
shows how to generate a random integer number within range.
A more complex random generation can be done with
SCV
(a very power full
package, which comes freely with systemc).
The
eighth
is generation of random data. The former example showed some simple cases to randomize
integers within range and randomization based on a specified distribution.
The
ninth
is a simple c++ example of pass variable to function by reference.
The
tenth
shows how to get an argument and pass it to function srand as its seed.
c++ SIGSEGV debug tip: two cases of SIGSEGV, which I have recently successfully debugged.
eleventh.
-
Most of the simple cpp examples are placed in a single directory and compiled using
this simple:
all purpose Makefile.
|