gpt4 book ai didi

c++ - 无法将参数 'std::string' 的 'std::string*' 转换为 '2'

转载 作者:行者123 更新时间:2023-11-30 03:04:44 26 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Partially Fill an array from a file

我不知道这是什么意思。我所有的变量都排成一行。我似乎找不到任何错误。

我也收到错误 error:no match for 'operator<<' in 'infile << names'如果您用 numoftoys 替换名称,这会给我带来另一个错误。

/***************************************************/
/* Author: Sam LaManna */
/* Course: */
/* Assignment: Program 6 Elves */
/* Due Date: 11/22/11 */
/* Filename: program6.cpp */
/* Purpose: Write a program that will process */
/* the work done by santas elfs */
/***************************************************/

#include <iostream> //Basic input/output
#include <iomanip> //Manipulators
#include <string> //String stuff
#include <fstream> //File input/output

using namespace std;

void instruct (); //Function Declaration for printing instructions
void input (ifstream &infile, string names [50], int numoftoys[50], int &i); //Function declaration for getting data from file

int main()
{

string names [50] = { }; //Array for storing names
int numoftoys [50] = { }; //Array for storing the number of toys made
int i = 0;

ifstream infile("eleves.dat"); //Opens input file "elves.dat"

instruct(); //Function call to print instructions

while (!infile.good())
{
input (infile, names[i] , numoftoys[i]);
++i;
}

cout << names << "\n" << "\n";

cout << numoftoys << "\n" << "\n";




return 0;
}




/***************************************************/
/* Name: instruct */
/* Description: Prints instructions to user */
/* Parameters: N/A */
/* Return Value: N/A */
/***************************************************/

void instruct ()
{
cout << "\n" << "This program will calculate the toys made by santas elfs and assign" << "\n";
cout << "a rating to each elf. It will also sort them and print average, min and max." << "\n";
cout << "\n" << "Make sure you have a file named elves.dat in the same directory as";
cout << "this porgram or you will recieve errors.";
cout << "\n" << "\n";

return;
}


/***************************************************/
/* Name: input */
/* Description: Reads from file */
/* Parameters: N/A */
/* Return Value: N/A */
/***************************************************/

void input (ifstream &infile, string names [50], int numoftoys[50], int &i)
{
infile << names;
infile << numoftoys;
infile.ignore ('\n');

return;
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com