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

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';
}

thanks mate it was very helpful

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.