Visual C++ 2010 Winform Errors C2238, C2059, C1075.
- by tracelez
It errors when I try compile. I cut the code out of the program and the program works and complies correctly. Not sure why it doesn't like this. This part of the code does single digit math with numeric strings that are converted into a char arrays.
**
Error 2 error C2238: unexpected token(s) preceding ';' C:\Users\Alpha\documents\visual studio 2010\Projects\Win32 Form c++\Win32 Form c++\Win32 Form c++.cpp 10 1 Win32 Form c++
**
Error 1 error C2059: syntax error : 'namespace' C:\Users\Alpha\documents\visual studio 2010\Projects\Win32 Form c++\Win32 Form c++\Win32 Form c++.cpp 10 1 Win32 Form c++
**
Error 3 error C1075: end of file found before the left brace '{' at 'c:\users\alpha\documents\visual studio 2010\projects\win32 form c++\win32 form c++\Form1.h(40)' was matched C:\Users\Alpha\documents\visual studio 2010\Projects\Win32 Form c++\Win32 Form c++\Win32 Form c++.cpp 23 1 Win32 Form c++
//////
//////
// chX[] and chY[] are char arrays from functional part of program
std::reverse( chX, &chX[ strlen( chX ) ] );
std::reverse( chY, &chY[ strlen( chY ) ] );
// makes sure x is larger or equal to y...makes looping logic easier
if (strlen(chX) < strlen(chY))
{
char *chZ = chX;
chX = chY;
chY = chZ;
}
//Variables for this part of the program
char chX2; char chY2; std::string strSum;
int sum = 0; bool carryth1 = false; int x=0; int y=0;
for (int i = 0; i <= (strlen(chX)-1); i++)
{
if (i <= strlen(chY)-1)
{
chX2= chX[i];
chY2= chY[i];
x = atoi(chX2);
y = atoi(chY2);
//x = atoi(chX[i]);
sum = x+y+(int)carryth1;
carryth1 = false;
if (sum > 9)
{
if(i == 0)
{
sum -=10;
strSum = itoa(sum);
carryth1 = true;
}
else
{
sum -=10;
strSum += itoa(sum);
carryth1 = true;
}
}
else
{
if(i == 0)
{
strSum = itoa(sum);
}
else
{
strSum += itoa(sum);
}
}
else
{
y = 0;
chX2= chX[i];
x = atoi(chX2);
sum = x+y+(int)carryth1;
if((i == strlen(chX)-1)&& (carryth1 == true) && (x == 9))
{
strSum += "10";
}
else
{
strSum = itoa(sum);
}
}
std::reverse( strSum, &strSum[ strlen( strSum ) ] );
//Creates new string for txtDisplay this simplifies conversions
String^ strDisplay = "X is " + gcnew String((strX1.c_str())) + " Y is " +gcnew String((strY1.c_str())) + " \r\n " ;
strDisplay += "The sum of the X + Y = ";
txtDisplay->Text = gcnew String((strSum.c_str())) ;