Could you post your program's source code as well?
tux4life
Nearly a Posting Maven
2,350 posts since Feb 2009
Reputation Points: 2,134
Solved Threads: 243
If you don't want to post your code, then maybe a cut down version. But the quickest way to do it yourself is to compile with debug info on and then run and wait till it crashes. The backtrace will tell you what memory component has been corrupted. It may take a little to work out what has actually happened as another array may have over writen it. The debugger can help listing the symbol and memory addresses.
You can also try valgrind. http://valgrind.org . Which finds memory errors/leaks etc. [with a few false positives.] This is also very good at finding array boundary errors.
Typical things you will find are memory that is assigned but not deleted. Memory that is created with new but deleted with free() and vis-vera. Array over runs. e.g
// runtime error
int A[10];
for(int i=0;i<=10;i++)
A[i]=i;
etc.
Similar things happen in char* because people overwrite the end of the array. If all the warnings are not on then you can do this
// WRONG code:
char *A="Enter key"
std::cout<<"A == "<<A<<std::endl;
std::cin>>A;
This works if the entry is less than 9 characters long.
StuXYZ
Practically a Master Poster
680 posts since Nov 2008
Reputation Points: 760
Solved Threads: 138
I really don't think that the problem is with string. Examining you code fragment, buffer2 obviously has size (you could test this with a
std::cout<<"Length of buffer2 == "<<buffer2.length()<<std::endl;
You haven't done something horrible like have your own local version of string ?? and then the horrific using namespace std; that everyone seems to add has caused you some problems. Basically you are going to need to look at your debugger.
StuXYZ
Practically a Master Poster
680 posts since Nov 2008
Reputation Points: 760
Solved Threads: 138
I used the Deleaker in such a case, and it always helped me to find not trivial errors and bugs.
Deleaker costs money, and probably you even don't get as much features as the free Valgrind (as already mentioned in one of the previous posts).
tux4life
Nearly a Posting Maven
2,350 posts since Feb 2009
Reputation Points: 2,134
Solved Threads: 243