Now, I'm reading a file, then checking each line and putting each character into a char[]
. However, when I run a for loop
and plus i
equal to string length
, the program developed in Visual Studio 2010 will crash. But, when I developed on my laptop which installed Visual Studio 2012, the final character will be \0
.
For example:
while(getline(infile, str)) {
char buf[1024];
int index = 0;
for (int i = 0; i < str.length(); i++) {
while(str[i] != ',' && str[i] != '\0') {
buf[index++] = str[i++];
}
}
}
It will crash when I use Visual Studio 2010 but success in Visual Studio 2012. Does anyone know the reason? What is the last element of string? Isn't is a \0
? Or it's a compiler problem ? If there's anything insufficient, please tell me to add.