2015-12-02 3 views
1

Я получаю несколько ошибок для индексов массивов, а также никакой подходящей функции для вызова для получения строки ... Я точно не знаю, почему именно.недопустимые типы для индексов массива

ошибка: "ИНТ [ИНТ] недопустимый типа для массива подстрочного

ошибка: недопустимый типа 'двойной [INT]' для массива подстрочного

ошибка:" ИНТ [ИНТ] недопустимый типа для массива подстрочный

ошибка: нет функции соответствия для вызова 'GetLine (BOOL)'

вот мой код до сих пор:

#include <iostream> 
#include <fstream> 
#include <cstring> 
#include <cstdlib> 
#include <iomanip> 
using namespace std; 

struct CountiesFirst 
{ 
    int counties; 
    double poverty_rate; 
    double income; 
}; 

const int MAX_COUNTIES = 10; 

bool openFile(ifstream& input) 
{ 
    int counties; 
    double poverty_rate; 
    double income; 
    int i=0; 
    char filename[256]; 

    cout << "Welcome to the Appalachian Poverty/Income Report\n"; 
    cout << "Enter input file name: "; 
    cin >> filename; 

    input.open(filename); 
    getline(input, counties); 

    while (getline(!input.eof() && i < MAX_COUNTIES)) 
    { 
    input>>counties[i]; 
    input>> poverty_rate[i] >> income[i]; 
    ++i; 
    } 
    while (input.eof()) 
    { 
    input.putback (i) ; 
    cout << "Input file is empty" << endl; 
    return i; 
    } 

    return !input.fail(); 
    } 

    void printTable(string counties[], 
     double poverty_rate[], 
     double income[], 
     size_t size) 
    { 
    cout << "Counties  Poverty Rate  Salary\n"; 
    cout << "---------------------------------------\n"; 
    for (size_t i = 0; i < size; ++i) 
    { 
    cout.width(17); 
    cout << left << counties[i]; 
    cout << poverty_rate[i] << "%"; 
    cout.width(13); 
    cout << right << "$" << income[i] << endl; 
    } 
} 


    int main() 
    { 
    CountiesFirst counties [MAX_COUNTIES]; 
    int filename; 

    ifstream input; 
    ofstream output; 

    if (openFile(input)) 
    { 
    //sort(counties, poverty_rate, income, size); 
    void printTable(string counties[], double poverty_rate[], double income[],  int size); 
    } 
    else 
    { 
    cout << "Input file does not exist.\n"; 
    exit(EXIT_FAILURE); 

    input.close(); 
    output.close(); 
    } 
    return 0; 
} 
+0

'getline (! Input.eof() && i

+0

'cin >> filename;' Это опасно. Что делать, если пользователь вводит более 255 символов? Используйте 'std :: string' –

+0

Кажется, что ваш код имеет бесконечные проблемы. Если бы я был вами, я бы переписал код с самого начала. – cpplearner

ответ

0
  1. Здесь:

    int counties; 
    double poverty_rate; 
    
    input >> counties[i]; 
    input >> poverty_rate[i] >> income[i]; 
    

    Вы пытаетесь работать с int и double как они являются массивами. Они не.
    Ошибка при создании недопустимых типов для индекса массива.

  2. getline принимает istream и string как аргументы.

    В то же время, здесь вы передаете int:

    int counties; 
    getline(input, counties); 
    

    Здесь вы делаете что-то совершенно неправильно:

    getline(!input.eof() && i < MAX_COUNTIES) 
    

    Он производит "без согласования функции" ошибка.

Смежные вопросы