S
sd2004
Hi,
I am getting compiling error on the following line.
I could not figure it out.
Could someone please kindly help me fixing the error ?
//////////////////////////// Error message ////////////////////
bash-2.05b$ g++ test5c.cpp
test5c.cpp:20: error: parse error before numeric constant
test5c.cpp: In function `int main()':
test5c.cpp:36: error: `11' cannot be used as a function
test5c.cpp: At global scope:
test5c.cpp:48: error: parse error before numeric constant
////////////////// Below is the code ////////////////////////////////
#include<iostream>
#include <string>
#include<vector>
#include<sstream>
#include<fstream>
using namespace std;
struct astruct
{
string name;
int id;
string type;
};
#define goldenretriever 11
#define Lab 33
#define Boxer 44
#define Terrier 55
void goldenretriever (astruct& astructref); //line 20
int main()
{
vector<astruct> v;
astruct astr;
ifstream in ("test5c.txt");
string line;
while (getline(in,line)){
istringstream anyname(line);
anyname>>astr.name>>astr.id>>astr.type;
v.push_back(astr);
}
vector<astruct>::iterator search;
for (search=v.begin();search!=v.end();++search){
switch (search->id){
case goldenretriever:
goldenretriever(search->name); //line 36
break;
case Lab:
cout <<search->name <<" is Lab. "<<endl;
default:
break;
break;
}
}
return 0;
}
void goldenretriever (search->name& s){ //line 48
cout <<s->name <<" is GoldenRetriever "<<endl;
//cout <<search->name <<" is GoldenRetriever "<<endl;
}
//////////////////////// input "test5c.txt"
//////////////////////////////////
cricket 11 GoldenRetriever
nitro 11 GoldenRetriever
Maxtor 33 Lab
Aaxtor 44 Boxer
Dora 55 Terrier
I am getting compiling error on the following line.
I could not figure it out.
Could someone please kindly help me fixing the error ?
//////////////////////////// Error message ////////////////////
bash-2.05b$ g++ test5c.cpp
test5c.cpp:20: error: parse error before numeric constant
test5c.cpp: In function `int main()':
test5c.cpp:36: error: `11' cannot be used as a function
test5c.cpp: At global scope:
test5c.cpp:48: error: parse error before numeric constant
////////////////// Below is the code ////////////////////////////////
#include<iostream>
#include <string>
#include<vector>
#include<sstream>
#include<fstream>
using namespace std;
struct astruct
{
string name;
int id;
string type;
};
#define goldenretriever 11
#define Lab 33
#define Boxer 44
#define Terrier 55
void goldenretriever (astruct& astructref); //line 20
int main()
{
vector<astruct> v;
astruct astr;
ifstream in ("test5c.txt");
string line;
while (getline(in,line)){
istringstream anyname(line);
anyname>>astr.name>>astr.id>>astr.type;
v.push_back(astr);
}
vector<astruct>::iterator search;
for (search=v.begin();search!=v.end();++search){
switch (search->id){
case goldenretriever:
goldenretriever(search->name); //line 36
break;
case Lab:
cout <<search->name <<" is Lab. "<<endl;
default:
break;
break;
}
}
return 0;
}
void goldenretriever (search->name& s){ //line 48
cout <<s->name <<" is GoldenRetriever "<<endl;
//cout <<search->name <<" is GoldenRetriever "<<endl;
}
//////////////////////// input "test5c.txt"
//////////////////////////////////
cricket 11 GoldenRetriever
nitro 11 GoldenRetriever
Maxtor 33 Lab
Aaxtor 44 Boxer
Dora 55 Terrier