Problem with test class pro, from C++ for dummies.
I have copied the following piece of code from c++ for dummies...
#include <iostream> #include <cstdio> #include <cstdlib> #include <string.h> using namespace std; class NameDataSet { public: char firstName[128]; char lastName [128]; int creditCard; }; bool getData(NameDataSet& nds); void displayData(NameDataSet& nds); int main(int nNumberofArgs, char* pszArgs[]) { const int MAX = 25; NameDataSet nds[MAX]; std::cout << "Read name/credit card information\n" << "Enter 'exit' to quit" << endl; int index = 0; while (getData(nds[index]) && index < MAX) { index++; } std::cout << "\Entries:" << endl; for (int i = 0; i < index; i++) { displayData(nds[i]); } system("PAUSE"); return 0; } bool getData(NameDataSet& nds) { std::cout << "\nEnter first name:"; cin >> nds.firstName; if (stricmp(nds.firstName, "exit") == 0) { return false; } std::cout << "Enter last name:"; cin >> nds.lastName; cout << "Enter credit card number:"; cin >> nds.creditCard; return true; } void displayData(NameDataSet& nds) { std::cout << nds.firstName << " " << nds.lastName << "/ " << nds.creditCard << endl; } ... now, when I compile it with "g++ class.cpp -o class", I get the following message. george@linux:~> g++ class.cpp -o class class.cpp: In function `bool getData(NameDataSet&)': class.cpp:47: error: `stricmp' undeclared (first use this function) class.cpp:47: error: (Each undeclared identifier is reported only once for each function it appears in.) george@linux:~> ... I've been looking at the code, and I don't see where "stricmp" is located at in the code. I don't know if it is a function, or something that should have been declared (or initialized?) earlier in the program. I'm pretty confident that this is not an error in the authors wrighting, but then I be ignorant to believe that "I know". |
You need to include <cstring>, not <string.h>. Also, it is inconsistent in its usage of "using namespace std;". Either get rid of std:: everywhere, or put it in where nessecery and get rid of the using.
|
Your gonna hit yourself when you see this:
It's a comparsion call... It should probably be strgcmp(string 1, string 2); Check line 47 :) Mistro116 |
I'm not sure what to do. What I wrote down is exactly what is showed. Line 47 is what is says. And I changed string.h to cstring. Still can't seem to get where I need to. I'll probably go on some online resource to find out how classes can be used. I have an idea, but I need to see it in action to fully understand it.
|
It might be a typo. Try changing it from stricmp(string 1, string2) to strcmp(string1, string 2).
|
instead of
Code:
stricmp(nds.firstName, "exit") Code:
strcasecmp(nds.firstName, "exit") oh by the way this did compile when I changed that line. |
Alright, ty, I will try that as soon as I get home. Thanx again for the posts guys.
|
All times are GMT -5. The time now is 08:20 AM. |