Hi, I am trying to convert a string vector to a double vector in c++ , but for some reason I am getting this error message. Hope you can help! Thanks
error: cannot convert ‘std::string {aka
std::basic_string<char>}’ to ‘const char*’ for argument ‘1’
to ‘double atof(const char*)’
double salary = atof(info[x].stringsalary);
my code is...
void display(vector<Employee_Data>& info){
double total = 0;
cout << "id" <<setw(25) <<"first name"
<<setw(25) <<"last name" <<setw(25)
<<"gender" <<setw(25) <<"department"
<<setw(25) <<"salary" << endl ;
for(int x=0; x<info.size();x++){
cout<<info[x].id<<setw(25)<<info[x].first_name<<setw(25)<<info[x].last_name<<setw(25)<<info[x].department<<setw(25)<<info[x].gender<<setw(25)<<
info[x].stringsalary<<endl;
double salary = atof(info[x].stringsalary);
total =+ salary;
}
cout << total;
}
void display(vector<Employee_Data>& info){
double total = 0;
cout << "id" <<setw(25) <<"first name"
<<setw(25) <<"last name" <<setw(25)
<<"gender" <<setw(25) <<"department"
<<setw(25) <<"salary" << endl ;
for(int x=0; x<info.size();x++){
cout<<info[x].id<<setw(25)<<info[x].first_name<<setw(25)<<info[x].last_name<<setw(25)<<info[x].department<<setw(25)<<info[x].gender<<setw(25)<<
info[x].stringsalary<<endl;
//double salary = atof(info[x].stringsalary);//atof only works when
given string to it,is a Ctype character array string
//so, first convert to Ctype character string, then pass it to
atof
//#include <bits/stdc++.h>
//s.c_str() by this you can get character array
string s=info[x].stringsalary;
double salary = atof(s.c_str());
total =+ salary;
}
cout << total;
}
Hi, I am trying to convert a string vector to a double vector in c++ ,...
Please help fix my code C++, I get 2 errors when running. The code should be able to open this file: labdata.txt Pallet PAG PAG45982IB 737 4978 OAK Container AYF AYF23409AA 737 2209 LAS Container AAA AAA89023DL 737 5932 DFW Here is my code: #include <iostream> #include <string> #include <fstream> #include <vector> #include <cstdlib> #include <iomanip> using namespace std; const int MAXLOAD737 = 46000; const int MAXLOAD767 = 116000; class Cargo { protected: string uldtype; string abbreviation; string uldid; int...
I am trying to modify this program so that it stores the employee's name in a c-string and can handle up to 100 employees (so it would mostly be a partially filled array), but I cannot get it to work. It works with two files that it is suppose to read input from. Then it prints output to an output file. Employee Info File (first file read, M/F should be ignored): 5 Christine Kim 30.00 2 1 F 15 Ray...
Hello I need a small fix in my program. I need to display the youngest student and the average age of all of the students. It is not working Thanks. #include <iostream> #include <iomanip> #include <fstream> #include <vector> #include <algorithm> using namespace std; struct Student { string firstName; char middleName; string lastName; char collegeCode; int locCode; int seqCode; int age; }; struct sort_by_age { inline bool operator() (const Student& s1, const Student& s2) { return (s1.age < s2.age); // sort...
This is c++ programming and here is my code. I am getting an exception thrown on the destructor for permanentworker. Can you tell me why I am getting this exception? #include <iostream> #pragma warning(disable:4996) class PermanentWorker { private: char *name; int salary; public: PermanentWorker(const char* nam, int money) : salary(money) { name = new char[strlen(nam) + 1]; strcpy(name, nam); } int getPay() const { return salary; ...
Hello, I need to implement these small things in my C++ code. Thanks. 1- 10 characters student first name, 10 characters middle name, 20 characters last name, 9 characters student ID, 3 characters age, in years (3 digits) 2- Open the input file. Check for successful open. If the open failed, display an error message and return with value 1. 3- Use a pointer array to manage all the created student variables.Assume that there will not be more than 99...
Need to implement Account.cpp and AccountManager.cpp code //Account.hpp #ifndef _ACCOUNT_HPP_ #define _ACCOUNT_HPP_ #include <string> using std::string; class Account { public: Account(); Account(string, double); void deposit(double); bool withdraw(double); string getName() const; double getBalance() const; private: string name; double balance; }; #endif ////////////////////////////////////////////// //AccountManager.hpp #ifndef _ACCOUNT_MANAGER_HPP_ #define _ACCOUNT_MANAGER_HPP_ #include "Account.hpp" #include <string> using std::string; class AccountManager { public: AccountManager(); AccountManager(const AccountManager&); //copy constructor void open(string); void close(string); void depositByName(string,double); bool withdrawByName(string,double); double getBalanceByName(string); Account getAccountByName(string); void openSuperVipAccount(Account&); void closeSuperVipAccount(); bool getBalanceOfSuperVipAccount(double&) const;...
C++ problem. hi heys, i am trying to remove beginning and the end whitespace in one file, and output the result to another file. But i am confused about how to remove whitespace. i need to make a function to do it. It should use string, anyone can help me ? here is my code. #include <iostream> #include <iomanip> #include <cstdlib> #include <fstream> using namespace std; void IsFileName(string filename); int main(int argc, char const *argv[]) { string inputfileName = argv[1];...
This is C++. The task is to convert the program to make use of fucntions, but I am am struggling to figure out how to do so. #include <iostream> #include <iomanip> using namespace std; main(){ char empid[ 100 ][ 12 ]; char fname[ 100 ][ 14 ], lastname[ 100 ][ 15 ]; int hw[ 100 ]; double gp[ 100 ], np[ 100 ], hr[ 100 ], taxrate[100], taxamt[ 100 ]; int counter = 0; int i; cout<<"ENTER EMP ID,...
Hello, I am trying to get this Array to show the summary of NETPAY but have been failing. What is wrong? #include <iostream> #include <iomanip> using namespace std; main(){ char empid[ 100 ][ 12 ]; char fname[ 100 ][ 14 ], lastname[ 100 ][ 15 ]; int sum; int hw[ 100 ]; double gp[ 100 ], np[ 100 ], hr[ 100 ], taxrate[100], taxamt[ 100 ]; int counter = 0; int i; cout<<"ENTER EMP ID, FNAME, LNAME, HRS...
C++ Programming
Hi! Sorry for all the material attached. I simply need help in
writing the Facility.cpp file and the other files are included in
case they're needed for understanding. I was able to complete the
mayday.cpp file but am stuck on Facility. The following link
contains a tar file with the files provided by the professor. Thank
you so much in advanced!
http://web.cs.ucdavis.edu/~fgygi/ecs40/homework/hw4/
Closer.h:
#ifndef CLOSER_H
#define CLOSER_H
#include <string>
#include "gcdistance.h"
struct Closer {
const double latitude, longitude;...