Array of Structures Program

Hey. I have a program that is suppose to use an array of structures to create a computer database. If someone could help me get rid of my errors. Thanks.

The code:

//C++Libraries
#include <fstream>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>

using namespace std;

const int MaxComps=100; //Maximum number of computers

struct CompInfo{
string ModelName;
string ManufacturerName;
string Price;
};

CompInfo comps[MaxComps];

int main(){
//Variable Declarations
ifstream iFile;//input computer system stream
ifstream inFile;//input command file stream
ofstream oFile; //output file stream
int counter;
string command;
string sort;
string temp;
int i;
string manufacturer;
string manufacturername;
int q;
bool found;
string model;
string modelname;
int w;
string price;
string lbound;
string ubound;
string next;


//The following statement prepare the input and output files for use
iFile.open("CompSys.txt");//opens the computer system file
inFile.open("Script.txt");//opens the command file
oFile.open("CompLog.txt");//opens the output file

//Print Header Info to output file
oFile<<"Programmer: "<< "Nicole Beck" << endl;
oFile<<"CS 1044 Program 5 2011"<<endl;
oFile<<"-----------------------------------------"<<endl;

//To Read iFile into Struct Array
for (int counter=0; counter<MaxComps; counter++){
getline(iFile, comps[counter].ModelName, " ");
getline(iFile, comps[counter].ManufacturerName, " ");
getline(iFile, comps[counter].Price, " ");
}

//Comman File Part
while (inFile){
inFile>>command;
inFile.ignore(80, '\t');
if (command==sort){
oFile<<"Sorting by price"<<endl;
oFile<<"-----------------------------------------"<<endl;
for (i=0; i<=counter; i++){
if (comps[i].Price>comps[i+1].Price){
string temp;
temp=comps[i].Price;
comps[i].Price=comps[i+1].Price;
comps[i+1].Price=temp;
}
}
}
else if (command==manufacturer){
inFile>>manufacturername;
oFile<<"Looking for Computers from: "<<manufacturername<<endl;
int q=0;
bool found=0;
for (q=0; q<MaxComps; q++){
if (comps[q].ManufacturerName==manufacturername){
oFile<<q<<"."<<comps[q].ModelName<<" "<<comps[q].ManufacturerName<<" "<<comps[q].Price<<endl;
found=1;
break;
}
}
if (!found){
oFile<<manufacturername<<"not found"<<endl;
}
oFile<<"-----------------------------------------"<<endl;
}
else if (command==model){
modelname = "";
inFile.get(next);
while(next != '\n' && next != '\t'){
modelname += next;
inFile.get(next);
}
oFile<<"Looking for Computer Named: "<<modelname<<endl;
int w=0;
for(w=0; w<=counter; w++){
if (command==model){
if (comps[w].ModelName == modelname){
oFile<<w<<'.'<<comps[w].ModelName<<' '<<comps[w].ManufacturerName<<' ' << comps[w].Price<<endl;
found = 1;
break;
}
}
}
if (!found){
oFile<<modelName<<"not found"<<endl;
}
}
else if (command==update){
inFile>>model;
inFile.ignore(80, '\t');
inFile>>price;
oFile<< "Updating Price for: " + model<<endl;
int i = 0;
bool found = 0;
for(i = 0; i < MaxComps; i++){
if(comps[i].ModelName == model){
comps[i].Price = price;
oFile<<i<<'.'<<comps[i].ModelName << ' '<<comps[i].ManufacturerName<<' ' << comps[i].Price<<endl;
found = 1;
break;
}
}
if(!found){
oFile<<"Model not found.\n";
}

oFile<<"-------------------------------------------------------"<<endl;
}
else if (command==range){
inFile>>lBound;
inFile.ignore(80, '\t');
inFile>>uBound;
oFile<<"Looking for Computers between" <<' '<< lBound <<' '<< "and"<<' ' <<uBound<<endl;
int i = 0;
for(i = 0; i < MaxComps; i++){
if(comps[i].Price >= lBound && comps[i].Price <= uBound){
oFile<i<<'.'<<comps[i].ModelName<<" "<<comps[i].ManufacturerName<<comps[i].Price<<endl;
}
}
oFile<<"-------------------------------------------------------"<<endl;
}
else {
oFile<< "Exit command found";
}
}
}

Last edited on
The errors i get are:
1>c:\users\owner\desktop\folders\college\fall 2011\cs 1044\projects\program 5 try 2\program 5 try 2\program 5 try 2.cpp(67): error C2780: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &)' : expects 2 arguments - 3 provided
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\string(479) : see declaration of 'std::getline'
1>c:\users\owner\desktop\folders\college\fall 2011\cs 1044\projects\program 5 try 2\program 5 try 2\program 5 try 2.cpp(67): error C2784: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std::ifstream'
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\string(468) : see declaration of 'std::getline'
1>c:\users\owner\desktop\folders\college\fall 2011\cs 1044\projects\program 5 try 2\program 5 try 2\program 5 try 2.cpp(67): error C2782: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem)' : template parameter '_Elem' is ambiguous
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\string(468) : see declaration of 'std::getline'
1> could be 'const char *'
1> or 'char'
1>c:\users\owner\desktop\folders\college\fall 2011\cs 1044\projects\program 5 try 2\program 5 try 2\program 5 try 2.cpp(67): error C2780: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &&,std::basic_string<_Elem,_Traits,_Alloc> &)' : expects 2 arguments - 3 provided
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\string(448) : see declaration of 'std::getline'
1>c:\users\owner\desktop\folders\college\fall 2011\cs 1044\projects\program 5 try 2\program 5 try 2\program 5 try 2.cpp(67): error C2784: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &&,std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &&' from 'std::ifstream'
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\string(395) : see declaration of 'std::getline'
1>c:\users\owner\desktop\folders\college\fall 2011\cs 1044\projects\program 5 try 2\program 5 try 2\program 5 try 2.cpp(67): error C2782: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &&,std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem)' : template parameter '_Elem' is ambiguous
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\string(395) : see declaration of 'std::getline'
1> could be 'const char *'
1> or 'char'
1>c:\users\owner\desktop\folders\college\fall 2011\cs 1044\projects\program 5 try 2\program 5 try 2\program 5 try 2.cpp(68): error C2780: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &)' : expects 2 arguments - 3 provided
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\string(479) : see declaration of 'std::getline'
1>c:\users\owner\desktop\folders\college\fall 2011\cs 1044\projects\program 5 try 2\program 5 try 2\program 5 try 2.cpp(68): error C2784: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std::ifstream'
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\string(468) : see declaration of 'std::getline'
1>c:\users\owner\desktop\folders\college\fall 2011\cs 1044\projects\program 5 try 2\program 5 try 2\program 5 try 2.cpp(68): error C2782: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem)' : template parameter '_Elem' is ambiguous
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\string(468) : see declaration of 'std::getline'
1> could be 'const char *'
1> or 'char'
1>c:\users\owner\desktop\folders\college\fall 2011\cs 1044\projects\program 5 try 2\program 5 try 2\program 5 try 2.cpp(68): error C2780: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &&,std::basic_string<_Elem,_Traits,_Alloc> &)' : expects 2 arguments - 3 provided
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\string(448) : see declaration of 'std::getline'
1>c:\users\owner\desktop\folders\college\fall 2011\cs 1044\projects\program 5 try 2\program 5 try 2\program 5 try 2.cpp(68): error C2784: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &&,std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &&' from 'std::ifstream'
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\string(395) : see declaration of 'std::getline'
1>c:\users\owner\desktop\folders\college\fall 2011\cs 1044\projects\program 5 try 2\program 5 try 2\program 5 try 2.cpp(68): error C2782: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &&,std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem)' : template parameter '_Elem' is ambiguous
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\string(395) : see declaration of 'std::getline'
1> could be 'const char *'
1> or 'char'
1>c:\users\owner\desktop\folders\college\fall 2011\cs 1044\projects\program 5 try 2\program 5 try 2\program 5 try 2.cpp(69): error C2780: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &)' : expects 2 arguments - 3 provided
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\string(479) : see declaration of 'std::getline'
1>c:\users\owner\desktop\folders\college\fall 2011\cs 1044\projects\program 5 try 2\program 5 try 2\program 5 try 2.cpp(69): error C2784: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std::ifstream'
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\string(468) : see declaration of 'std::getline'
1>c:\users\owner\desktop\folders\college\fall 2011\cs 1044\projects\program 5 try 2\program 5 try 2\program 5 try 2.cpp(69): error C2782: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem)' : template parameter '_Elem' is ambiguous
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\string(468) : see declaration of 'std::getline'
1> could be 'const char *'
1> or 'char'
1>c:\users\owner\desktop\folders\college\fall 2011\cs 1044\projects\program 5 try 2\program 5 try 2\program 5 try 2.cpp(69): error C2780: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &&,std::basic_string<_Elem,_Traits,_Alloc> &)' : expects 2 arguments - 3 provided
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\string(448) : see declaration of 'std::getline'
and: 1>c:\users\owner\desktop\folders\college\fall 2011\cs 1044\projects\program 5 try 2\program 5 try 2\program 5 try 2.cpp(69): error C2784: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &&,std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &&' from 'std::ifstream'
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\string(395) : see declaration of 'std::getline'
1>c:\users\owner\desktop\folders\college\fall 2011\cs 1044\projects\program 5 try 2\program 5 try 2\program 5 try 2.cpp(69): error C2782: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &&,std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem)' : template parameter '_Elem' is ambiguous
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\string(395) : see declaration of 'std::getline'
1> could be 'const char *'
1> or 'char'
1>c:\users\owner\desktop\folders\college\fall 2011\cs 1044\projects\program 5 try 2\program 5 try 2\program 5 try 2.cpp(107): error C2664: 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::get(_Elem &)' : cannot convert parameter 1 from 'std::string' to 'char &'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1>c:\users\owner\desktop\folders\college\fall 2011\cs 1044\projects\program 5 try 2\program 5 try 2\program 5 try 2.cpp(108): error C2678: binary '!=' : no operator found which takes a left-hand operand of type 'std::string' (or there is no acceptable conversion)
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\system_error(425): could be 'bool std::operator !=(const std::error_code &,const std::error_condition &)'
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\system_error(432): or 'bool std::operator !=(const std::error_condition &,const std::error_code &)'
1> while trying to match the argument list '(std::string, char)'
1>c:\users\owner\desktop\folders\college\fall 2011\cs 1044\projects\program 5 try 2\program 5 try 2\program 5 try 2.cpp(108): error C2678: binary '!=' : no operator found which takes a left-hand operand of type 'std::string' (or there is no acceptable conversion)
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\system_error(425): could be 'bool std::operator !=(const std::error_code &,const std::error_condition &)'
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\system_error(432): or 'bool std::operator !=(const std::error_condition &,const std::error_code &)'
1> while trying to match the argument list '(std::string, char)'
1>c:\users\owner\desktop\folders\college\fall 2011\cs 1044\projects\program 5 try 2\program 5 try 2\program 5 try 2.cpp(108): fatal error C1903: unable to recover from previous error(s); stopping compilation
the third argument to getline should be a char, not a string.
1
2
3
getline(iFile, comps[counter].ModelName, ' ');
getline(iFile, comps[counter].ManufacturerName, ' ');
getline(iFile, comps[counter].Price, ' ');


next should be of type char, not std::string

You wrote modelName instead of modelname

You used update and range without having variables with that name.

You used lBound and uBound when it the variables are called lbound and ubound.

At the end you wrote oFile<i<<... instead of oFile<<i<<...




Last edited on
Topic archived. No new replies allowed.