Click here to Skip to main content
15,904,655 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Alright, so when I run my code I get a compile error that says exactly what my subject title says. I know why it does that, and it's because on line 71 i'm trying read string values into arrays that have been declared as ints. I'm not exactly sure how to go about fixing the problem so any help would be appreciated. Here is the code below:

#include <fstream>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>

using namespace std;

const int MAX_COMP = 50;
const int MAX_MANU = 50;
const int MAX_PRICE = 50;

struct Computer
{
	string Model;
	string Manu;
	int Price;
	string ARRAY1[100];
	string ARRAY2[100];
	int ARRAY3[100];
		
};
struct Database
{
Computer DB[MAX_COMP][MAX_MANU][MAX_PRICE];
};

void getComputer(Computer&, ifstream&, ofstream&, Database&);

//void sortComputer(int ARRAY3[], int size);

int main()
{
	Computer data;
	Database base;
	
	ifstream iFile;
	ofstream oFile;
	iFile.open("CompSys.txt");
	oFile.open("CompLog.txt");


	getComputer(data, iFile, oFile, base);
	
	iFile.close();
	oFile.close();
	return 0;


}

void getComputer(Computer& data, ifstream& iFile, ofstream& oFile, Database& base)
{

	int Idx = 0;
	
	while(!iFile.eof()&& Idx<100)
	{
		
	getline(iFile, data.Model, '\t');
	data.ARRAY1[Idx] = data.Model;
	
	getline(iFile, data.Manu, '\t');
	data.ARRAY2[Idx] = data.Manu;

	iFile >> data.Price;
	data.ARRAY3[Idx] = data.Price;

	Idx++;

	base.DB[data.ARRAY1[Idx]][data.ARRAY2[Idx]][data.ARRAY3[Idx]]; //Line # 71

	}
	
	

	cout<<data.ARRAY1[0]<<" "<<data.ARRAY2[0]<<" "<<data.ARRAY3[0];
	
}
Posted
Updated 23-Nov-11 12:12pm
v2
Comments
Sergey Alexandrovich Kryukov 23-Nov-11 14:35pm    
Do you like riddles? Why not providing comprehensive error/exception information? In this case, your compiler tells you exact line and exact error message. Why not indicating it all? Not only you failed to understand what a compiler requires, but you also failed to provide this information in full. OK, line 71... Is is so difficult to mark it in your code? Why anyone would search for everything for you?
--SA
CeePlusNewb 23-Nov-11 18:20pm    
my mistake. no need to be a jerk
Albert Holguin 23-Nov-11 15:27pm    
Uhm... we can't see your line numbers, so use C/C++ style comments to point out lines that you refer to in your code (for the future).
CeePlusNewb 23-Nov-11 18:20pm    
sorry, thanks man.
JackDingler 23-Nov-11 16:03pm    
What are you trying to accomplish with this line?

base.DB[data.ARRAY1[Idx]][data.ARRAY2[Idx]][data.ARRAY3[Idx]];

1 solution

You still have the problem of your structs being used in the wrong way. Your Computer should encapsulate the details of a single object rather than containing arrays of other items. Your Database does not need to be a structure as it just contains a multidimensional array, which is unnecessary; you just need a simple one dimensional array of Computer objects which is filled in as you get the details from your file.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900