Daniel Del Core
Daniel Del Core

Reputation: 3221

Converting Vector * to char *

I'm having a problem converting my pointer to a vector to a char *. Here is my code, what is it that I'm doing wrong?

char * Word1 = (*fileRead)[i].c_str();
char * Word2 =  dict[j].c_str();

if(WordCmp(Word1,Word2)
{
    found = true;   
}

Here is the function header for WordCmp().

int WordCmp(char* Word1, char* Word2);

The error I'm getting is the following:

server.cpp:200: error: invalid conversion from 'const char*' to 'char*'
server.cpp:201: error: invalid conversion from 'const char*' to 'char*'

Upvotes: 2

Views: 398

Answers (1)

datenwolf
datenwolf

Reputation: 162164

The compiler tells you, that the type of the pointer is a "pointer to a cost char", but you're trying to assign it to a pointer to a (mutable) char.

Replace the first two lines with

const char * Word1 = (*fileRead)[i].c_str();
const char * Word2 =  dict[j].c_str();

Upvotes: 5

Related Questions