For example, the following code reverses a string, but what actually goes on when I'm adding each character to a string? Is it efficient? Does it create a new char array every time, or does it double the size every time it fills up, or?:
#include <iostream>
#include <stack>
using namespace std;
int main()
{
string test = "testing";
stack<char> first;
for(int i = 0; test[i]; i++)
{
first.push(test[i]);
}
string reversed;
int i=0;
while(!first.empty())
{
reversed += first.top();
first.pop();
}
cout << test << reversed;
}