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?

Recommended Answers

All 8 Replies

You could just do it like this:

int number = atoi(map.c_str());

A int is not going to hold a number that big. Use __int64 instead.

__int64 n = atoi("11111111111111");

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

So you want to convert it into an int array?

Member Avatar for iamthwee

Or you can use a bignum library.

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.

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

Thanks firstPerson. That did the trick.

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.