String problem i Visual C++ .NET
Fortsættelse af spgm: "http://exp.dk/spm/239381"Hvis man stepper nedenstående igennem og holder øje med s1, vil man se at efter 3 gennemløb, så indeholder s1 ligepludselig noget crap!!
// test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream.h>
#include <string>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
string s1, s2;
long int x;
char chBuf[30];
s1="Antal";
s2=" loops";
s1=s1+s2;
for(x=0;x<100+1;x++)
{
sprintf(chBuf, "%s%s%d", "", " ", x);
s1+=chBuf;
}
return 0;
}
Jeg fatter det ikke!!!?