编译错误::没有找到类型为'std :: string'的全局运算符 [英] Compile error :: no global operator found which takes type 'std::string'

查看:331
本文介绍了编译错误::没有找到类型为'std :: string'的全局运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以当我运行我的代码时,我得到一个编译错误,该错误恰好说明了我的主题标题所说的内容.我知道为什么会这样做,这是因为在第71行中,我试图将字符串值读入已声明为int的数组中.我不确定如何解决该问题,因此将不胜感激.这是下面的代码:

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];
	
}

推荐答案

您仍然遇到struct使用错误的问题.您的Computer应该封装单个对象的详细信息,而不是包含其他项的数组.您的Database不必是一个结构,因为它只包含一个多维数组,这是不必要的.您只需要一个简单的Computer对象的一维数组,当您从文件中获取详细信息时就将其填充.
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.


这篇关于编译错误::没有找到类型为'std :: string'的全局运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆