0

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;
}

Edited by alexchen: n/a

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by arkoenig
0

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.

1

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.