I'm getting an error compiling a simple program using c++ in linux. There are 3 files: Employee.h , Employee.cpp, and Salary.cpp (main). I'm including several system headers in Salary.cpp <iostream>, <fstream>, <string>, <stdio.h>, <stdlib.h> The only reason I'm using is for the itoa() function. I could not get it to compile and read somewhere that '' is sometimes a prerequisite.
The error I get is: 'Salary.cpp:195:47: error: itoa was not declared in this scope
Now, I i've included the headers in the global scope, and itoa() is only used in the file that I include so I don't know why this would happen other than it is not including the correct system headers. Do I need to specify all the system headers in the command line or something? I'm not quite sure what is going on.
Edit: Here is some of the source code...I've only expanded on what is needed to keep it short. The error occurs in the addEmployee() function near the bottom...i'm not sure I know how to put line numbers. It's right after create a new Employee()
#include "Employee.h"
#include <iostream>
#include <fstream>
#include <string>
#include <cstdio>
#include <cstdlib>
void findEmployees(Employee*[], const short);
void addEmployee(Employee*[], short&);
unsigned short parseDataFile(Employee* [], short);
bool insertEmployee(Employee*[], short, Employee*);
int main(int argc, char** argv)
{
//100 employees max, too lazy to create dynamic container
Employee* employeeList[100];
//Parse data file, return the length of the list made
short listLen = parseDataFile(employeeList, 100);
//Employee database is built, run query engine
std::cout << "*************************************************\n";
std::cout << "This program lets you search for salaries of employees or input new employee information.\n";
std::cout << "*************************************************\n\n\n";
char choice = { 0 };
while (true)
{
std::cout << "Please choose an option: \n";
std::cout << "(1) Search for employee salaries.\n";
std::cout << "(2) Input new employee data\n";
std::cout << "(3) Exit\n\n";
std::cin >> choice;
switch (choice)
{
case '1':
findEmployees(employeeList, listLen - 1);
break;
case '2':
addEmployee(employeeList, listLen);
break;
case '3':
exit(0);
break;
}
}
return 0;
}
unsigned short parseDataFile(Employee* empList[], short len)
{
//Do stuff
}
void findEmployees(Employee* empList[], const short len)
{
//Do stuff
}
void addEmployee(Employee* empList[], short& len)
{
char first[32] = "";
char last[32] = "";
char salary[32] = "";
char id[32] = "";
bool loop = true;
while (loop)
{
std::cout << "Input Last Name: ";
std::cin.clear();
std::cin.sync();
std::cin.getline(last, 31);
std::cout << std::endl << std::endl;
std::cout << "Input First Name: ";
//Get user name
std::cin.clear();
std::cin.sync();
std::cin.getline(first, 31);
std::cout << std::endl << std::endl;
std::cout << "Input Salary: $";
//Get user name
std::cin.clear();
std::cin.sync();
std::cin.getline(salary, 31);
std::cout << std::endl << std::endl;
Employee* employee = new Employee();
employee->setID( itoa((int)len, id, 10) ); //Set id
employee->setFirstName(first); //Set first name
employee->setLastName(last); //Set last name
employee->setSalary(salary); //Set salary
//Inserts new employee at the end of the list, no real reason to sort the list for this assignment
//I guess I could have used std::vector to make it easy
empList[len] = employee;
++len; //Increment length of the list
char yesNo = { 0 };
std::cout << "Would you like to enter another employee? (Y, N): ";
std::cin >> yesNo;
std::cout << std::endl << std::endl;
switch (yesNo)
{
case 'Y':
case 'y':
//do nothing
break;
case 'N':
case 'n':
loop = false;
break;
}
}
}
<cstdlib>and<cstdio>so that those functions are in thestdnamespace.