So i have a string (example : "1 12 69 123") and i want to put each of the space separated integers into an array of integers . the number of integers is known ( in this case 4 ) . Thanks in advance :3
Ps . i know it's not relevant to the framework . don't be too mad
Ps2 . array of std::vector is also acceptable
Convert string into array of ints
Re: Convert string into array of ints
unsigned int NDigits( int num )
{
return log10(num) + 1;
}
char buffer[100] = "(your string here)";
std::vector<int> nums;
unsigned int index = 0;
const unsigned int size = strlen(buffer);
while(index < size)
{
nums.push_back(atoi(&buffer[index]));
index += (NDigits(nums.back()) + 1);
}
Note you must include math.h
Just curious are you in a programming class?
Try that out, good luck!
{
return log10(num) + 1;
}
char buffer[100] = "(your string here)";
std::vector<int> nums;
unsigned int index = 0;
const unsigned int size = strlen(buffer);
while(index < size)
{
nums.push_back(atoi(&buffer[index]));
index += (NDigits(nums.back()) + 1);
}
Note you must include math.h
Just curious are you in a programming class?
Try that out, good luck!
Computer too slow? Consider running a VM on your toaster.