hello im new to c++ and im trying out this exercise from a book where i have to convert list of char* to c style strings then convert it to a vector of strings.
here's the code:
Code:
#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>
#include <list>
using namespace std;
int main()
{
list<char*> c;
c.push_back("hi");
c.push_back("fu");
c.push_back("ga");
vector<string> sv;
char** c2=new char*[c.size()];
for (int i=0; i < 2; i++)
c2[i]=new char[2];
// convert to c style strings
for (list<char*>::iterator j=c.begin(); j!=c.end(); ++j)
{
static int i=0;
c2[i]=*j;
++i;
}
// convert to vector of strings
for (char**p=c2; p < c2+c.size(); ++p)
sv.push_back(*p);
for (vector<string>::iterator i=sv.begin(); i!=sv.end(); ++i)
cout << *i << endl;
// the codes below seem to cause the problem. i use free version of visual c++ and when i exclude the code below, the program runs fine.
for (int i=0; i<c.size(); ++i)
delete []c2[i];
delete [] c2;
system("pause");
return 0;
}
visual c++ generates an error message:
Debug Assertion Failed!
Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)