2 Replies - 3171 Views - Last Post: 21 October 2009 - 02:58 PM Rate Topic: -----

#1 xumin85007  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 19-October 09

cannot convert from 'const char [2]' to 'char'

Post icon  Posted 21 October 2009 - 02:55 PM

i dont know what's wrong with this. it says " cannot convert from 'const char [2]' to 'char'"
pls help me thanks

this is one of function in my code.
it seems i can't use the command line[a]="*" to put"*" into the array?
void display(int i)
{
	char * line=new char[i];
	for(int a=0;a<=i;++a)
			line[a]="*";
}


This post has been edited by xumin85007: 21 October 2009 - 02:56 PM


Is This A Good Question/Topic? 0
  • +

Replies To: cannot convert from 'const char [2]' to 'char'

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6107
  • View blog
  • Posts: 23,661
  • Joined: 23-August 08

Re: cannot convert from 'const char [2]' to 'char'

Posted 21 October 2009 - 02:57 PM

This:
"*"
is not a character. Because you've enclosed it in double-quotes, that's a string of two characters, the * character and the NULL-terminator character. Try using single quotes.
Was This Post Helpful? 0
  • +
  • -

#3 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3120
  • View blog
  • Posts: 19,164
  • Joined: 14-September 07

Re: cannot convert from 'const char [2]' to 'char'

Posted 21 October 2009 - 02:58 PM

You're using double quotes, chars need single quotes:

line[a] = '*';


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1