0

Hi mates

So i have a big project for my school...and the bad news are that i am a noob in C++..

In VCL enviroment i try to take an AnsiString Text from a listbox or EditBox and convert it into a integer array in order to do some calculatos with other integer arrays i have in a class that i have defined. The text i would like to convert is asequence of integers with a space between them
ie. 0 1 9 12 78 0 1

I use the c_str() function to convert the Ansistring to a cstring but then i don't know how to pass each numerical digit(s) as an element of an integer array.
For the case above i would like to have

int a[7];
a[1]=0
a[2]=1
a[3]=9
a[4]=12
etc

thanks in advance

mike

2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by zourlas
0

A stringstream is the easiest way to do what you want:

#include <iostream>
#include <sstream>
#include <string>

int main()
{
  const char *p = "0 1 9 12 78 0 1";
  std::istringstream iss(p);
  int value;

  while (iss >> value)
    std::cout << value * 2 << '\n';
}
This topic has been dead for over six months. 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.