Error 1 error C2440: '=' : cannot convert from 'const char [2]' to 'char'

bool word(char *Filename){


int r,number,length;

ifstream file;
file.open(Filename);

file>>number;

srand ( (unsigned)time ( NULL ) );
r=rand() % number+1;


string input,word;

for(int i=0; i<r; i++) getline(file,input);
length=input.length();

for(int l=0;l<length;l++)word[l]="_";


cout<<input<<endl<<word<<endl;;




return true;
}

Recommended Answers

All 3 Replies

In line 20, change "_" to '_'

After you solve that problem I found a new one.It is not in my error list.

Debug Assertion failed.
Expression string out of range.

On line 15, you define a variable named "word." Because that is a string variable, it is automatically initialized to an empty string--that is, a string with no characters in it.

I do not see any place in the code you posted where you give a different value to that variable, which means that it is always going to be an empty string.

In line 20, you execute the statement word[l]='_', which is legitimate only if word has at least "l" characters in it. But we have already established that word does not have any characters in it. Therefore, this statement will always fail.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.