P
Peithon
Hi,
I'm trying to create a vector of strings and print the contents using
an iterator but I'm getting
an error with my very first string.
Can anyone help?
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
int main()
{
char* temp1 = NULL;
vector<string> vec;
vector<string>::iterator it1;
temp1 = new char[21];
strcpy(temp1, "Test String");
vec.push_back(temp1);
for(it1 = vec.begin(); it1 != vec.end(); it1++)
{
cout << "Test: " << *it1 << endl;
}
}
I'm trying to create a vector of strings and print the contents using
an iterator but I'm getting
an error with my very first string.
Can anyone help?
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
int main()
{
char* temp1 = NULL;
vector<string> vec;
vector<string>::iterator it1;
temp1 = new char[21];
strcpy(temp1, "Test String");
vec.push_back(temp1);
for(it1 = vec.begin(); it1 != vec.end(); it1++)
{
cout << "Test: " << *it1 << endl;
}
}