0

My c++ code

string map = "111111111111111111111111111"
for (int i = 0; i < 20; i++)
{
   int number = atoi(map[i]);
}

Gave me error: cannot convert parameter 1 from 'char' to 'const char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast

string map = "111111111111111111111111111"
 
for (int i = 0; i < 20; i++)
{
   std::istringstream ss(map[i]);
   
}

Gave me some error too.

How should I do that?

4
Contributors
8
Replies
10
Views
6 Years
Discussion Span
Last Post by Hektzu
Featured Replies
  • [QUOTE=Hektzu;1279445]No I want take one letter and convert that to integer. If that is not possible I have to use array or vector and size would be big.[/QUOTE] [code] char n1 = '1'; int num = n1 - '0'; //num equals 1 [/code] Read More

0

Amount if 1 in string is 300 so int value would be huge thats why I have to take single letter.

Edited by Hektzu: Typos

0

So you want to convert it into an int array?

No I want take one letter and convert that to integer. If that is not possible I have to use array or vector and size would be big.

1

No I want take one letter and convert that to integer. If that is not possible I have to use array or vector and size would be big.

char n1 = '1';
int num = n1 - '0'; //num equals 1
This question has already been answered. 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.