-2

I'm trying to solve this problem and i get such an error [ Invalid conversion from 'char' to 'const char' ] ,but i can't figure out how to solve it. Here are the lines in which the problem is :

Declarations:
string alp("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
string formatted;
char partoftext[20];
size_t found;

found = text.copy(partoftext,2,0);
partoftext[found] = '\0';
a = atoi(partoftext);
formatted.append(alp[a]);

...    

and the problem is in this line of code :

formatted.append(alp[a]);

thanks.

ddacot
  • 1,212
  • 3
  • 14
  • 40

2 Answers2

4

From :http://www.cplusplus.com/reference/string/string/append/

formatted.append(1, alp[a]);

/*
string& append ( const string& str );
string& append ( const string& str, size_t pos, size_t n );
string& append ( const char* s, size_t n );
string& append ( const char* s );
string& append ( size_t n, char c );
*/
AlexTheo
  • 4,004
  • 1
  • 21
  • 35
  • one more question, why it's showing zeroes instead of letters? http://ideone.com/92d5F – ddacot Apr 16 '12 at 07:49
  • It is not a 0 but 'O'. Also you could use supstr instead of copy and stringstream instead of atoi-> or take a look on boost::lexical_cast http://stackoverflow.com/questions/8065413/stdlexical-cast-is-there-such-a-thing – AlexTheo Apr 16 '12 at 08:10
0

If my guess is correct (and it's a guess because you don't specify what the error actually is), try:

formatted.append(alp, a, 1);

Not_a_Golfer
  • 47,012
  • 14
  • 126
  • 92