why can’t I print the copied string individually? [closed]

Because a is empty, a[i] accesses it out of bounds for every possible i, causing undefined behavior.

Use a.push_back(s[i]) to add characters to a.

Leave a Comment