Visual Studio throws and error with this code but web based compilers run it just fine? Specific error in VS is Debug Assertion failed! Expression: string iterator + offset out of range. Please help, any thoughts?
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
string alpha = "abcdefghijklmnopqrstuvwxyz{";
string::const_iterator x = alpha.begin(), x2;
for (int p = 1; p <= 14; ++p) {
int w, count = 0; // set to 0 each iteration
// output spaces
for (int k = 13; k >= p; --k)
cout << ' ';
x2 = x; // set starting point
// output first half of characters
for (int c = 1; c <= p; ++c) {
cout << *x2;
x2++; // move forwards one letter
count++; // keep count of iterations
}
// output back half of characters
for (w = 1, x2 -= 2; w < count; ++w) {
cout << *x2;
--x2; // move backwards one letter
}
x++; // next letter
cout << '\n';
}
return 0;
}