数组下标的类型无效
invalid types for array subscripts
我在数组下标中遇到了几个错误,并且没有匹配的函数来调用获取行。。。我不知道为什么。
错误:数组下标的类型"int[int]"无效
错误:数组下标的类型"double[int]"无效
错误:数组下标的类型"int[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 Reportn";
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 Salaryn";
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;
}
-
此处:
int counties; double poverty_rate; input >> counties[i]; input >> poverty_rate[i] >> income[i];
您正在尝试使用
int
和double
,就像它们是数组一样。事实并非如此
它会产生"数组下标的无效类型"错误。 -
CCD_ 3以CCD_ 4和CCD_。
同时,您正在通过
int
:int counties; getline(input, counties);
这里你做了一件完全错误的事情:
getline(!input.eof() && i < MAX_COUNTIES)
它会产生"无匹配函数"错误。
相关文章:
- Openssl 1.1.1d无效使用不完整的类型"struct dsa_st"
- 多维数组 C++ 中数组下标的类型"int[int]"无效
- 如何解决一元"*"(有"字符")错误的无效类型参数?
- "错误:数组下标的无效类型'float [10001][float]'是什么意思?
- C++ 从两类中确定无效类型*
- 数组下标编译的无效类型'int[int]'由于 -Wfatal 错误而终止
- 数组下标的无效类型INT [INT]
- 此背包代码显示浮点[float]无效类型错误.可能是什么原因
- 我收到"无效类型 int[int]...",但这毫无意义
- 数组下标的无效类型"<未解析的重载函数类型>[int]" - C++
- 一元*的类型冲突error和无效类型参数具有int
- 映射迭代器:一元'*'的无效类型参数(具有"int")
- 一元 '*' 的 #define 和无效类型参数(具有 'double')
- 使用矢量的数组下标'int[int]'无效类型
- 数组相关错误 - 无效类型.
- 未知语法无效(类型::m_function)()
- 如何修复"'一元*'的无效类型参数?
- 高斯-赛德尔函数中的无效类型
- 数组下标和其他无效类型"int[int]"
- 我面临这个:我的程序中数组下标的无效类型"double[int]"