Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++;并在文件上输出 我试图做一个C++程序,做这样的事情: 在姓氏和姓名列表(文件)中,阅读另一个文件中的相同姓氏并盖章“姓氏的人有:姓名、姓名、姓名等。”。。 我就是这么做的,但是出了点问题 #include <iostream> #include <fstream> #include <string> using namespace std; struct persona { string nome; string cognome; }; int carica_vettore (persona a []) { string name, surname; int i=0, np=0; ifstream fin ("people.txt"); while (cin >> name >> surname) { if (name == "0" && surname == "0") break; a[i].nome = name; a[i].cognome = surname; i++; np++; } return np; } int main () { string nomepers, cognomepers; int cont = 0; persona persone [50]; cont = carica_vettore(persone); for (int k = 0; k < cont; k++) { for (int j = k+1; j < cont-1; j++) if (persone[k] == persone[j]) cout << "People with surname (" << persone[i] << "), are: " << persone[i].nome; } return 0; } #包括 #包括 #包括 使用名称空间std; 结构人物 { 字符串名称; 字符串同源; }; int carica_vettore(角色a[]) { 字符串名称、姓氏; int i=0,np=0; ifstream fin(“people.txt”); 而(cin>>姓名>>姓氏) { 如果(姓名==“0”和姓氏==“0”) 打破 a[i].nome=名称; a[i].cognome=姓氏; i++; np++; } 返回np; } int main() { 字符串命名词,同源词; int cont=0; 个人形象[50]; cont=加勒比(个人); 对于(int k=0;k C++编译提供隐式运算符。@瓦伦蒂内克-在这种情况下,你能解释OP在他们的问题评论中所说的编译错误吗?我很好奇。是的,我忘了在PurOne中添加CynOM[I],对,我忘了在PurOne中添加CynOM[I]。_C++_Arrays_String_File_For Loop - Fatal编程技术网 >姓名>>姓氏) { 如果(姓名==“0”和姓氏==“0”) 打破 a[i].nome=名称; a[i].cognome=姓氏; i++; np++; } 返回np; } int main() { 字符串命名词,同源词; int cont=0; 个人形象[50]; cont=加勒比(个人); 对于(int k=0;k C++编译提供隐式运算符。@瓦伦蒂内克-在这种情况下,你能解释OP在他们的问题评论中所说的编译错误吗?我很好奇。是的,我忘了在PurOne中添加CynOM[I],对,我忘了在PurOne中添加CynOM[I]。,c++,arrays,string,file,for-loop,C++,Arrays,String,File,For Loop" /> >姓名>>姓氏) { 如果(姓名==“0”和姓氏==“0”) 打破 a[i].nome=名称; a[i].cognome=姓氏; i++; np++; } 返回np; } int main() { 字符串命名词,同源词; int cont=0; 个人形象[50]; cont=加勒比(个人); 对于(int k=0;k C++编译提供隐式运算符。@瓦伦蒂内克-在这种情况下,你能解释OP在他们的问题评论中所说的编译错误吗?我很好奇。是的,我忘了在PurOne中添加CynOM[I],对,我忘了在PurOne中添加CynOM[I]。,c++,arrays,string,file,for-loop,C++,Arrays,String,File,For Loop" />

C++;并在文件上输出 我试图做一个C++程序,做这样的事情: 在姓氏和姓名列表(文件)中,阅读另一个文件中的相同姓氏并盖章“姓氏的人有:姓名、姓名、姓名等。”。。 我就是这么做的,但是出了点问题 #include <iostream> #include <fstream> #include <string> using namespace std; struct persona { string nome; string cognome; }; int carica_vettore (persona a []) { string name, surname; int i=0, np=0; ifstream fin ("people.txt"); while (cin >> name >> surname) { if (name == "0" && surname == "0") break; a[i].nome = name; a[i].cognome = surname; i++; np++; } return np; } int main () { string nomepers, cognomepers; int cont = 0; persona persone [50]; cont = carica_vettore(persone); for (int k = 0; k < cont; k++) { for (int j = k+1; j < cont-1; j++) if (persone[k] == persone[j]) cout << "People with surname (" << persone[i] << "), are: " << persone[i].nome; } return 0; } #包括 #包括 #包括 使用名称空间std; 结构人物 { 字符串名称; 字符串同源; }; int carica_vettore(角色a[]) { 字符串名称、姓氏; int i=0,np=0; ifstream fin(“people.txt”); 而(cin>>姓名>>姓氏) { 如果(姓名==“0”和姓氏==“0”) 打破 a[i].nome=名称; a[i].cognome=姓氏; i++; np++; } 返回np; } int main() { 字符串命名词,同源词; int cont=0; 个人形象[50]; cont=加勒比(个人); 对于(int k=0;k C++编译提供隐式运算符。@瓦伦蒂内克-在这种情况下,你能解释OP在他们的问题评论中所说的编译错误吗?我很好奇。是的,我忘了在PurOne中添加CynOM[I],对,我忘了在PurOne中添加CynOM[I]。

C++;并在文件上输出 我试图做一个C++程序,做这样的事情: 在姓氏和姓名列表(文件)中,阅读另一个文件中的相同姓氏并盖章“姓氏的人有:姓名、姓名、姓名等。”。。 我就是这么做的,但是出了点问题 #include <iostream> #include <fstream> #include <string> using namespace std; struct persona { string nome; string cognome; }; int carica_vettore (persona a []) { string name, surname; int i=0, np=0; ifstream fin ("people.txt"); while (cin >> name >> surname) { if (name == "0" && surname == "0") break; a[i].nome = name; a[i].cognome = surname; i++; np++; } return np; } int main () { string nomepers, cognomepers; int cont = 0; persona persone [50]; cont = carica_vettore(persone); for (int k = 0; k < cont; k++) { for (int j = k+1; j < cont-1; j++) if (persone[k] == persone[j]) cout << "People with surname (" << persone[i] << "), are: " << persone[i].nome; } return 0; } #包括 #包括 #包括 使用名称空间std; 结构人物 { 字符串名称; 字符串同源; }; int carica_vettore(角色a[]) { 字符串名称、姓氏; int i=0,np=0; ifstream fin(“people.txt”); 而(cin>>姓名>>姓氏) { 如果(姓名==“0”和姓氏==“0”) 打破 a[i].nome=名称; a[i].cognome=姓氏; i++; np++; } 返回np; } int main() { 字符串命名词,同源词; int cont=0; 个人形象[50]; cont=加勒比(个人); 对于(int k=0;k C++编译提供隐式运算符。@瓦伦蒂内克-在这种情况下,你能解释OP在他们的问题评论中所说的编译错误吗?我很好奇。是的,我忘了在PurOne中添加CynOM[I],对,我忘了在PurOne中添加CynOM[I]。,c++,arrays,string,file,for-loop,C++,Arrays,String,File,For Loop,将cin替换为fin 您也没有为persona重载operator==: bool operator==(persona const& other) const { return nome == other.nome && cognome == other.cognome; } 还有操作符你不是想从文件中读取吗 ifstream fin("people.txt"); while(cin >> name >> surname) // cin

cin
替换为
fin

您也没有为
persona
重载
operator==

bool operator==(persona const& other) const
{
    return nome == other.nome && cognome == other.cognome;
}

还有
操作符你不是想从文件中读取吗

ifstream fin("people.txt");
while(cin >> name >> surname) // cin reads from the console, waits for your input
cin
替换为
fin

您也没有为
persona
重载
operator==

bool operator==(persona const& other) const
{
    return nome == other.nome && cognome == other.cognome;
}


还有
操作符
if(persone[k]==persone[j])
是问题所在。错误消息会告诉您哪里错了,行号是什么。您正在比较两个Persona结构,但不能对它们使用
=
操作符。也许您应该改为比较它们的nome或cognome值。

if(persone[k]==个人[j])
就是问题所在。错误消息会告诉您什么是错误的,行号是什么。您正在比较两个Persona结构,但不能对它们使用
=
运算符。也许您应该比较它们的nome或cognome值。

您的程序到底出了什么问题?您得到了什么输出?它会崩溃吗?请更新请用更多信息回答您的问题。@KLibby不盖章,它崩溃是的,我无法获得输出。还有此错误:39 17[error]与“operator==”不匹配(操作数类型为“persona”和“persona”)它怎么会崩溃而不同时编译?@LogicStuff如果我试图删除它,这将崩溃。你不能仅仅通过删除问题行来修复编译错误!你需要修复它们!请参阅下面的答案。你的程序到底出了什么问题?你得到了什么输出?它会崩溃吗?请用更多信息更新你的问题。@KLibby不盖章,它崩溃是的,我无法获得输出。还有此错误:39 17[error]与“operator==”不匹配(操作数类型为“persona”和“persona”)它怎么会崩溃而不同时编译?@LogicStuff如果我尝试删除它,这会崩溃你不能通过删除问题行来修复编译错误!你需要修复它们!请参见下面的答案。nome e cognome应该在结构向量中,如果我记得的话,我已经使用==它们是,但你不能使用
=
o我想我明白了。我必须比较cognome[k]和cognome[j]?@KLibby,他当然可以使用
operator==()<结构>由于使用C++,C++编译提供隐式运算符。@ ValualTimeNuq-在这种情况下,你能解释OP在他们的问题评论中所说的编译错误吗?我很好奇。NoME的认知应该在结构向量中,如果我记得,我已经使用了= =它们,但是你不能使用<代码> = = < /COD>直接在结构上,这就是你要做的。哦,是的,我明白了,我想。我必须比较cognome[k]和cognome[j]?@KLibby,他当然可以使用
操作符==()在使用C++的结构中, > C++编译提供隐式运算符。@瓦伦蒂内克-在这种情况下,你能解释OP在他们的问题评论中所说的编译错误吗?我很好奇。是的,我忘了在PurOne中添加CynOM[I],对,我忘了在PurOne中添加CynOM[I]。