Convert string char * to std :: string

1

I have the following code:

void splitstr(std::string &modulo, std::string &nmodulo, int &fk)
{
    string frase = modulo;
    string aux = "";
    stringstream strs;

    for (int i = 0; i < frase.length(); i++)
    {
       switch(frase[i])
       {
            case 'c':
                aux = "";
                break;
            default:
                aux = aux + frase[i];
                break;
       }
    }

    nmodulo = aux;
    strs(nmodulo);

    strs >> fk;
}

Whose error is:

  

error: no match for call to '(std :: stringstream {aka   std :: basic_stringstream}) (std :: string &) '

    
asked by anonymous 29.09.2015 / 16:55

1 answer

2

Conversion from std :: string to const char * just use the function c_str () of str :: string, eg:

std::string str= "String";
const char * ch_prt= str.c_str();

Conversion from std :: string to char * just use the function c_str () of str :: string and copy to char *, eg:

std::string str= "String";
char * ch_prt = (char*) calloc(str.length()+1, sizeof(char*));
strcpy(ch_prt, str.c_str());

Conversion of char * or const char * to std :: str just use direct cast, eg:

char * ch_prt = "LOL";
std::string str = (std::string) ch_prt;
    
16.11.2015 / 17:59