The segmentation fault is due to memory access violation - dereferencing invalid pointer:
for( int i = 1; i <= argc; i++)
{
args.push( string( argv[ i]));
}
When there are argc
arguments sent to a program the last one is indexed with argc - 1
.
for( int i = 0; i < argc; i++) // includes also a name of a program, argv[ 0]
{
args.push( string( argv[ i]));
}
or:
for( int i = 1; i < argc; i++) // excludes a name of a program, argv[ 0]
{
args.push( string( argv[ i]));
}
I suggest a use of debuger. It will show you the line causing a fault so you can investigate invalid pointer.
Change also to:
for( int i=0; i < args.size(); ++i)
{
arg = args.front();