This works as it should, but I now need to modify my code and include all numbers from 2400 to 2800 . Is there a way I can do this in a simpler way than writing all 400 numbers, like i.e 2400-2800 in the first line?
You want to write the numbers 2400 to 2800 to a string, with a colon between each number?
Non-standard (uses itoa which is not standard):
1 2 3 4 5 6 7 8 9 10
string target;
char buffer [5];
for (int i=2400; i<2801; ++i)
{
target = target + itoa(i, buffer, 10);
if (i!=2800) // Don't add one right on the end
{
target = target+":";
}
}
Standard:
1 2 3 4 5 6 7 8 9 10
stringstream target;
for (int i=2400; i<2801; ++i)
{
target << i;
if (i!=2800) // Don't add one right on the end
{
target<< ":";
}
}
string outputString = target.str();
You now have a C++ string with the data you want. If you need a C style char pointer, you can get one from the string object.
NOTE: i have not included the definition of many of the functions referred to, but i have revealed in their identifiers their purpose. So it should not be too hard to create them.
There are probably other ways of doing this, but this concept works for me.
string *findNumbers(string elem){string *p=new string[number of elements expected];
short y=0;
for(short x=0;elem[x]!='\0';x++){