S
Samuele Armondi
Hi everyone,
Since istringstream objects are not assignable, I'm using the following code
to allocate some dynamically. My question is: Is this the correct way of
doing it? Am I deleting all the allocated memory correctly? Or am I missing
something glaringly simple?
Thanks in advance,
S. Armondi
std::istringstream** ArgStream;
std::string* TempStrings;
try
{
ArgStream = new std::istringstream*[CurrentCommandNumArgs];
TempStrings = new std::string[CurrentCommandNumArgs];
}
catch (const std::bad_alloc& exception)
{
REPORT(exception.what());
return NULL;
}
for (int n = 0; n < CurrentCommandNumArgs; ++n)
{
std::string::size_type pos = Arguments.find_first_of(',');
TempStrings[n] = Arguments.substr(0, pos);
Arguments.erase(0, ++pos);
std::cout<< (TempStrings[n]) << '\n';
try
{
ArgStream[n] = new std::istringstream(TempStrings[n]);
}
catch (const std::bad_alloc& exception)
{
REPORT(exception.what());
return NULL;
}
}
delete[] TempStrings;
// The istringstream objects get used here
for (n = 0; n < CurrentCommandNumArgs; ++n)
delete ArgStream[n];
delete[] ArgStream;
Since istringstream objects are not assignable, I'm using the following code
to allocate some dynamically. My question is: Is this the correct way of
doing it? Am I deleting all the allocated memory correctly? Or am I missing
something glaringly simple?
Thanks in advance,
S. Armondi
std::istringstream** ArgStream;
std::string* TempStrings;
try
{
ArgStream = new std::istringstream*[CurrentCommandNumArgs];
TempStrings = new std::string[CurrentCommandNumArgs];
}
catch (const std::bad_alloc& exception)
{
REPORT(exception.what());
return NULL;
}
for (int n = 0; n < CurrentCommandNumArgs; ++n)
{
std::string::size_type pos = Arguments.find_first_of(',');
TempStrings[n] = Arguments.substr(0, pos);
Arguments.erase(0, ++pos);
std::cout<< (TempStrings[n]) << '\n';
try
{
ArgStream[n] = new std::istringstream(TempStrings[n]);
}
catch (const std::bad_alloc& exception)
{
REPORT(exception.what());
return NULL;
}
}
delete[] TempStrings;
// The istringstream objects get used here
for (n = 0; n < CurrentCommandNumArgs; ++n)
delete ArgStream[n];
delete[] ArgStream;