|
From: <tam...@ms...> - 2002-09-07 16:47:44
|
Hey guys
I'm still very green at this and I just inputted a small program (listed =
below) from "Teach Yourself C++", and when I try to compile it gives me =
errors
LINE 26 PARSE ERROR BEFORE ';'
LINE 30 PARSE ERROR BEFORE ';'
I took the int i and the ++ off both lines and the program compiled but d=
idn't work properly. I was wondering is the book wrong or am I doing som=
ething wrong?
#include <iostream>
char msg[] =3D "Now is the time\n";
int main()
{
char* cp; //---a pointer to char
int i; //---an integer subscript
=20
//---Pointer access, pointer notation
for (cp =3D msg; *cp; cp++)
std::cout << *cp; =20
=20
//---Subscript access, subscript notation =20
for (i =3D 0; msg[i]; i++)
std::cout << msg[i]; =20
=20
//---Pointer access, subscript notation =20
for (cp =3D msg; cp[0]; cp++)
std::cout << cp[0];
=20
//---Subscript access, pointer notation
for (i =3D 0; *(msg+i); i++)
std::cout << *(msg+i);
=20
//---Pointer and subscript access, pointer notation
for (i =3D 0; cp =3D msg; *(cp+i); i++)
std::cout << *(cp+i);
=20
//---Pointer and subscript access, subscript notation
for (i =3D 0; cp =3D msg; cp[i]; i++)
std::cout << cp[i];
=20
//---system pause
char end;
std::cin >> end;
return 0;
}
|