对于_id; a[i]。设置\u id(用于\u id); infle>>用于销售; a[i].设置已售出(用于已售出); 填充>>以获取更多信息; a[i]。设置剩余(用于剩余); } } infle.close(); } int main(){ 项目sp[最大尺寸]; sp=read_In();**显然错误就在这里** 系统(“暂停”); 返回0; },c++,xcode,C++,Xcode" /> 对于_id; a[i]。设置\u id(用于\u id); infle>>用于销售; a[i].设置已售出(用于已售出); 填充>>以获取更多信息; a[i]。设置剩余(用于剩余); } } infle.close(); } int main(){ 项目sp[最大尺寸]; sp=read_In();**显然错误就在这里** 系统(“暂停”); 返回0; },c++,xcode,C++,Xcode" />

为什么我会犯错误;数组类型项[1000]不可赋值";? 我对C++很陌生,我需要对这个错误提供一些帮助。 '数组类型项[1000]不可分配'?顺便说一下,我在XCode上, 我知道我应该在窗户上。这是学校的家庭作业,所以如果你 如果你能指引我,而不付出太多,那就太棒了。哦,对不起 如果我把事情搞砸了,这是我的第一篇帖子 #include <iostream> #include <string> #include <fstream> using namespace std; //global constant const int MAX_SIZE = 1000; //make an Item class class Item { private: string id; int sold, remain; public: void set_id(string _id); void set_sold(int _sold); void set_remain(int _remain); }; //all the methods setting id, sold, and remaining void Item::set_id(string _id){ id = _id; } void Item::set_sold(int _sold){ sold = _sold; } void Item::set_remain(int _remain){ remain = _remain; } //code to read from file ifstream inFile; ofstream outFile; //function that reads file to array void read_In() **I think it's because this should not be a void** { //variables int ct = MAX_SIZE; Item a[MAX_SIZE]; //open the file inFile.open( "inventory.txt" ); //while the file hasn't ended, read and place into array of Items while( !inFile.eof() ){ string for_id = ""; int for_sold = 0; int for_remain = 0; for(int i = 0;i<ct;i++){ //store the next thing on the file to the array of Items inFile >> for_id; a[i].set_id(for_id); inFile >> for_sold; a[i].set_sold(for_sold); inFile >> for_remain; a[i].set_remain(for_remain); } } inFile.close(); } int main(){ Item sp[MAX_SIZE]; sp = read_In(); **Apparently the error is here!** system("pause"); return 0; } #包括 #包括 #包括 使用名称空间std; //全局常数 const int MAX_SIZE=1000; //制作一个项目类 类项目 { 私人: 字符串id; 出售,保留; 公众: 无效集合id(字符串id); 已售出的无效集合(已售出的整数); 无效集保持(int保持); }; //设置id、销售和剩余的所有方法 无效项::设置\u id(字符串\u id){ id=_id; } 无效项::已售出的集合(已售出的整数){ 已售出=_已售出; } 无效项::设置剩余(整数剩余){ 保持,保持; } //要从文件中读取的代码 河流充填; 出流孔的直径; //将文件读取到数组的函数 void read_In()**我认为这是因为这不应该是一个void** { //变数 int ct=最大尺寸; a项[最大尺寸]; //打开文件 infle.open(“inventory.txt”); //当文件尚未结束时,读取并放入项目数组中 而(!infle.eof()){ _id=“”的字符串; 已售出的_的整数=0; int表示_剩余=0; 对于(int i=0;i>对于_id; a[i]。设置\u id(用于\u id); infle>>用于销售; a[i].设置已售出(用于已售出); 填充>>以获取更多信息; a[i]。设置剩余(用于剩余); } } infle.close(); } int main(){ 项目sp[最大尺寸]; sp=read_In();**显然错误就在这里** 系统(“暂停”); 返回0; }

为什么我会犯错误;数组类型项[1000]不可赋值";? 我对C++很陌生,我需要对这个错误提供一些帮助。 '数组类型项[1000]不可分配'?顺便说一下,我在XCode上, 我知道我应该在窗户上。这是学校的家庭作业,所以如果你 如果你能指引我,而不付出太多,那就太棒了。哦,对不起 如果我把事情搞砸了,这是我的第一篇帖子 #include <iostream> #include <string> #include <fstream> using namespace std; //global constant const int MAX_SIZE = 1000; //make an Item class class Item { private: string id; int sold, remain; public: void set_id(string _id); void set_sold(int _sold); void set_remain(int _remain); }; //all the methods setting id, sold, and remaining void Item::set_id(string _id){ id = _id; } void Item::set_sold(int _sold){ sold = _sold; } void Item::set_remain(int _remain){ remain = _remain; } //code to read from file ifstream inFile; ofstream outFile; //function that reads file to array void read_In() **I think it's because this should not be a void** { //variables int ct = MAX_SIZE; Item a[MAX_SIZE]; //open the file inFile.open( "inventory.txt" ); //while the file hasn't ended, read and place into array of Items while( !inFile.eof() ){ string for_id = ""; int for_sold = 0; int for_remain = 0; for(int i = 0;i<ct;i++){ //store the next thing on the file to the array of Items inFile >> for_id; a[i].set_id(for_id); inFile >> for_sold; a[i].set_sold(for_sold); inFile >> for_remain; a[i].set_remain(for_remain); } } inFile.close(); } int main(){ Item sp[MAX_SIZE]; sp = read_In(); **Apparently the error is here!** system("pause"); return 0; } #包括 #包括 #包括 使用名称空间std; //全局常数 const int MAX_SIZE=1000; //制作一个项目类 类项目 { 私人: 字符串id; 出售,保留; 公众: 无效集合id(字符串id); 已售出的无效集合(已售出的整数); 无效集保持(int保持); }; //设置id、销售和剩余的所有方法 无效项::设置\u id(字符串\u id){ id=_id; } 无效项::已售出的集合(已售出的整数){ 已售出=_已售出; } 无效项::设置剩余(整数剩余){ 保持,保持; } //要从文件中读取的代码 河流充填; 出流孔的直径; //将文件读取到数组的函数 void read_In()**我认为这是因为这不应该是一个void** { //变数 int ct=最大尺寸; a项[最大尺寸]; //打开文件 infle.open(“inventory.txt”); //当文件尚未结束时,读取并放入项目数组中 而(!infle.eof()){ _id=“”的字符串; 已售出的_的整数=0; int表示_剩余=0; 对于(int i=0;i>对于_id; a[i]。设置\u id(用于\u id); infle>>用于销售; a[i].设置已售出(用于已售出); 填充>>以获取更多信息; a[i]。设置剩余(用于剩余); } } infle.close(); } int main(){ 项目sp[最大尺寸]; sp=read_In();**显然错误就在这里** 系统(“暂停”); 返回0; },c++,xcode,C++,Xcode,首先,正确关闭注释。一半的错误将被删除。其次,您正在使用 void read_In(){ 所以read\u In返回void.。那么您不能接受它的值,sp=read\u In()是错误的。该错误还提到了导致错误的代码行。错误在哪里?read\u In没有返回任何内容,因此您无法分配它(不存在)向变量返回值。首先read_In返回void意味着它不返回任何内容。其次,您不能将数组分配给数组,这不是语言的一部分。对于固定大小的数组,请使用std::array,如果需要可变大小的数组,请使用std:

首先,正确关闭注释。一半的错误将被删除。其次,您正在使用

void read_In(){

所以read\u In返回void.。那么您不能接受它的值,
sp=read\u In()
是错误的。

该错误还提到了导致错误的代码行。错误在哪里?
read\u In
没有返回任何内容,因此您无法分配它(不存在)向变量返回值。首先
read_In
返回
void
意味着它不返回任何内容。其次,您不能将数组分配给数组,这不是语言的一部分。对于固定大小的数组,请使用
std::array
,如果需要可变大小的数组,请使用
std::vector
。如果必须使用裸数组,请查看error非常清楚:数组是不可分配的函数不返回任何东西,但你要把它分配给某个东西。你应该把数组和大小作为参数。在一个侧面注意,在Oxx上写C++没有错,在XCODE或其他智能中,如果我改变Read in,就说是item Read in并返回一个项目,然后分配sp = Read in,这将是,还是i这被认为是非法的吗?
sp
是数组,您将返回单元素形式的read_In,对吗?因此,在这种情况下,您需要使用索引,例如,
sp[index]=read_In();