Powłoka systemu - problem z działaniem

0
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <unistd.h>
#include <sys/param.h>
#include <sys/types.h>
#include <dirent.h>
#include <fstream>
#include <sstream>
using namespace std;

#define NBUF 1024
string pobierzsciezke();
string polecenie;
const string domowy = pobierzsciezke();
const char * domowy_katalog = domowy.c_str();

//*****************************************************************************************

string pobierzsciezke()
{
    char buffer[NBUF];
    getcwd(buffer,NBUF);
    string ret(buffer);
    return ret;
}
void pwd()
{
    //funkcja podajaca sciezke korzystajaca z pobierzsciezke
    cout << pobierzsciezke() <<endl;
}

void cd(string argument2)
{
    const char *par2=argument2.c_str();
    if (argument2 == "")
        chdir(domowy_katalog);
    else
    {
        chdir(par2);
    }
}

void ls()
{
    DIR *dpdf;
    struct dirent *epdf;
    dpdf = opendir("./");
    if (dpdf != NULL)
    {
        while ((epdf = readdir(dpdf)))
        {
            cout << epdf->d_name << endl;
        }
    }
}

void kopiuj(string par2,string par3)
{
    ifstream plik1 (par2.c_str(), fstream::binary);
    if (!plik1.good() )
        cout << "plik nie istnieje" <<endl;
    else
    {
        ofstream plik2 (par3.c_str(), fstream::trunc|fstream::binary);
        if(!plik2.good())
            cout << "Nie mozna otworzyc pliku do zapisu" << endl;
        else
        {
            plik2 << plik1.rdbuf ();
            plik1.close();
            plik2.close();
            cout << " Wykonano " << endl;
        }
    }
}


void wypisz(string inp)
{
    ifstream plik1 (inp.c_str(), fstream::in);
    if (!plik1.good() )
        cout << " Plik nie istnieje lub brak dostepu " <<endl;
    else
    {
        cout << plik1.rdbuf ();
        cout << endl;
        plik1.close();
    }
}

void trojkat(string inp)
{
    int nParam = stod(inp,NULL);
    for (int i=0; i<nParam; ++i)
    {
        for (int j=i; j<nParam; ++j)
        {
            printf("*");
        }
        printf("\n");
    }
}

void pomoc()
{
    cout << endl;
    cout << " Mozliwe polecenia : "<< endl;
    cout << "'cd' 'ls' 'pwd' 'kopiuj' 'pomoc' 'wypisz' 'trojkat' 'exit'"<<endl;
    cout << " <nazwa polecenia> --pomoc (Wyswietla pomoc do danego polecenia)"<<endl;
    cout << " exit -konczy dzialanie programu "<< endl;
    cout << endl;
}

int main()
{
    pomoc();
    cout <<endl;
    while((polecenie !="exit") && (polecenie !="EXIT"))
    {
        cout << pobierzsciezke() <<" -> ";
        getline(cin,polecenie);

        string argument_1, argument_2, argument_3,argument_4,argument_5;
        istringstream StrStream(polecenie);

        StrStream >> argument_1;
        StrStream >> argument_2;
        StrStream >> argument_3;
        StrStream >> argument_4;
        StrStream >> argument_5;
        if(!argument_1.empty())
            cout << "argument_1: " <<  argument_1 << endl;
        if(!argument_2.empty())
            cout << "argument_2: " <<  argument_2 << endl;
        if(!argument_3.empty())
            cout << "argument_3: " <<  argument_3 << endl;
        if(!argument_4.empty())
            cout << "argument_4: " <<  argument_4 << endl;

        if (argument_2 == "--pomoc")
        {
            if (argument_1=="pwd")
                cout << "pwd - wyswietla aktualna sciezke "<<endl;
            else if (argument_1=="ls")
                cout << "ls - wyswietla listing biezacego katalogu "<< endl;
            else if (argument_1=="pomoc")
                cout << "pomoc - wyswietla liste mozliwych komend " <<endl;
            else if (argument_1=="cd")
                cout << "cd <sciezka> - zmienia katalog roboczy, cd - zmienia na domowy." <<
                     " cd / -zmienia na glowny. cd .. -cofa "<< endl;
            else if (argument_1=="kopiuj")
                cout << "kopiuj <plik zrodlowy> <plik docelowy> " <<
                     "- Kopiuje plik zrodlowy pod nowo nadana nazwa"<< endl;
            else if (argument_1=="wypisz")
                cout << "wypisz <plik> - Wypisuje zawartosc pliku jako tekst"<<endl;
            else if (argument_1=="trojkat")
                cout << "trojkat liczba - rysuje trojkat na podstawie liczby"<<endl;
        }
        else
        {
            if (argument_1 == "pwd")
                pwd();
            else if (argument_1 == "cd" && !argument_2.empty())
                cd(argument_2);
            else if (argument_1 == "ls")
                ls();
            else if (argument_1 == "kopiuj" && !argument_2.empty() && !argument_3.empty())
                kopiuj(argument_2,argument_3);
            else if (argument_1 == "pomoc")
                pomoc();
            else if (argument_1 == "wypisz" && !argument_2.empty())
                wypisz(argument_2);
            else if (argument_1 == "trojkat" && !argument_2.empty())
                trojkat(argument_2);
        }
    }
    return 0;
}


Błąd:

[error] 'stod' was not declared in this scope

Jest to kod który mam rozbudować, jednak jak mam to zrobić skoro się nie kompiluje. Pomoc, proszę D: ?

1

Na oko ta funkcja to jest jakieś ascii to int -> http://www.cplusplus.com/reference/cstdlib/atoi/
wiec zamień tą linijkę na atoi(inp) i powinno ruszyć.

1

Dodaj do kompilatora przełącznik:

 -std=c++11

stod jest od standardu c++11.

1 użytkowników online, w tym zalogowanych: 0, gości: 1