2011-12-07 5 views
1

2つの配列にファイルのデータを部分的に書き込む必要があります。しかし、私の現在のコードは、私にgiberishのようなエラーを与えます。誰かがエラーの解読を助けることさえできるのであれば、私は非常に感謝しています。部分的にファイルから配列を埋めよう

コード:

/***************************************************/ 
/* Author:  Sam LaManna       */ 
/* Course:  CSC 135 Lisa Frye     */ 
/* 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]); //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 

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

    instruct();  //Function call to print instructions 

    while (!infile.eof()) 
    { 
     input (names [50], numoftoys [50]); 
    } 

    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]) 
{ 
    infile >> names >> numoftoy; 
    infile.ignore ("\n"); 

    return; 
} 

エラー:

直接リンク:http://i.imgur.com/q7I4g.png

+0

テキストとしてエラーをしてください。そして、実際には、この種の「テクニカル・サポート」の質問はここで話題にはなりませんが、あなたが「宿題」とタグ付けして以来、少し余裕ができます。 –

答えて

2
istream::operator>> has overloads for neither arrays of strings nor arrays of integers. 

あなたは一度に一つの各文字列と各整数を読み込む必要があります。あなたは私たちがより多くのC++答えを提供できるのstd ::ベクトル、などを使用することを許可されている場合はもともと@Seth Carnegie

input (infile, names, numoftoys); //your call was completely wrong 

infile.ignore ('\n'); //notice the char instead of string 

infile >> names >> numoftoys; //this won't work like this but at least we fixed the declaration error 

によって掲示。また使用しないでください - using namespace std;

+0

名前空間を使用すると何が問題ですか? ?私が教えてくれたことだよ –

+0

@SamLaMannaさて、私は彼に電話できるように先生の番号を教えてください。これをチェックしてください:http://cboard.cprogramming.com/cplusplus-programming/117354-why-std-not-using-namespace-std.html – FailedDev

+1

@SamLaManna:C++の教えの質が広範囲に及ぶことを再び強調して世界。 [理由はこちら](http://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-a-bad-practice-in-c) –

関連する問題