I'm trying to write a function that takes a string array as a parameter, converts it to a int array, and returns the new array. I thought it would be pretty simple with the use of "Atoi" but apperently you cant use it the way i tried to.
here is my code so far.
int GameHandler::convertToInt(string array[])
{
int tmp=0;
string arr[20]=array;
int values[20];
for(int i=0;i<20;i++)
values[i]=0;
for(int i=0;i<20;i++)
{
tmp=atoi(arr[i]);
values[i]=tmp;
}
return values;
}
Here is the error msg i get from my compiler:
GameHandler.cpp: In member function ‘int GameHandler::convertToInt(std::string*)’: GameHandler.cpp:60:20: error: conversion from ‘std::string* {aka std::basic_string*}’ to non-scalar type ‘std::string {aka std::basic_string}’ requested GameHandler.cpp:67:24: error: cannot convert ‘std::string {aka std::basic_string}’ to ‘const char*’ for argument ‘1’ to ‘int atoi(const char*)’ GameHandler.cpp:71:12: error: invalid conversion from ‘int*’ to ‘int’ [-fpermissive] GameHandler.cpp:61:9: warning: address of local variable ‘values’ returned [enabled by default]