OS2 World.Com Forum

Subject  :  Newbie problem - String Class
Author  :  JGiacchi os2man4@yahoo.com
Date  :  22 Sep, 2002 on 22:56
I'm in a Comp Sci class at my high school and I'm trying to get a string to work. This is my program. My compiler is IBM Visualage 4.0 and the error i get is "MSG CPPC0063E: The text"{" is unexpected." Any help you could give me would be greatly appreciated.

#include <iostream.h>
#include <string.h>

void verse(string lanimal, string lsound)
{
cout << "Old MacDonald had a farm Ei Ei Ho and on that farm he had a " << ;
cout << lanimal << "Ei Ei Ho" << endl;
cout << "With a " << lsound << " " << lsound <<"here and a " << lsound << " " << lsound << "there." <<endl;
cout << "Here a " << lsound << "there a " << lsound << "everywhere a " << lsound << " " << lsound << "." <<endl
cout << "Old MacDonald had a farm Ei Ei Ho" << endl;
}
int main(string ganimal, string gsound)
{
cin >> ganimal;
cin >> gsound;
verse(gsound,ganimal);
return 0;
}


Build FIRST, ask questions later.

Subject  :  Re:Newbie problem - String Class
Author  :  JasonL fdt93@yahoo.com
Date  :  23 Sep, 2002 on 19:55
Correct me if I'm wrong, but I don't believe "string" is a valid data type in C / C++

Strings need to be declared in one of 2 ways:

1. An array of char 's: char lanimal[10];
2. a char pointer: char *lanimal;

This is assuming you did not create a user-defined type called "string" elsewhere in the code. I'm also not sure how using the wrong data type declaration would produce the error message you're getting.

Hope this helps.
JasonL


Subject  :  Re:Newbie problem - String Class
Author  :  JGiacchi os2man4@yahoo.com
Date  :  24 Sep, 2002 on 05:07
That did help thanks a lot.
Build FIRST, ask questions later.

Powered by UltraBoard 2000 <www.ub2k.com>