未在范围内声明.多个错误
Not declared in scope. Multiple errors
由于某种原因,我不断收到范围错误。我继续收到多个范围错误以及。
#include<iostream.h>
#include<fstream.h>
#include<assert.h>
void ScanInFile(int ScanInValues[], int *total)
{
int i=0;
while(!cin>>&ScanInValues[i].eof()){
i++;
*total = i;
}
}
void SortFile(int DataSetValues[], int TotalValues)
{
int i, j, temp;
for(i = 0; i < (TotalValues - 1); i++){
for(j=0; j < TotalValues - i -1; j++){
if(DataSetValues[j] > DataSetValues[j+1]){
temp = DataSetValues[j];
DataSetValues[j] = DataSetValues[j+1];
DataSetValues[j+1] = temp;
}
}
}
}
int main(void)
{
int i, AmountOfValues=0;
int values[100]={ 0 };
ScanInFile(values, &AmountOfValues);
SortFile(values, AmountOfValues);
for(i=0; i < AmountOfValues; i++){
cout<<values[i];
}
cout<<endl;
return 0;
}
由于某种原因,G++ 不会编译程序。我继续收到一个错误,说 endl 和 cout,而 eof 不在范围内。我哪里做错了?
这些对象在命名空间内声明std
。您可以在它们前面加上std::
(std::cout << ...
),或者在 cpp 文件的开头添加using namespace std;
。
修复 eof 错误后,您还需要检查数组的越界访问,因为您在写入之前从不检查大小。
除了 Eric 所说的之外,你的代码中还有更多问题需要指出。在您的 ScanInFile
函数中有一个您编写了这一行:
while (!cin >> &ScanInValues[i].eof())
此行将编译,但它将执行与预期非常不同的操作。我假设您正在此行执行提取,但希望在未到达文件末尾时执行这些提取。不需要.eof()
,因为流将通过隐式转换为布尔值来分析流状态本身。这是按以下方式完成的:
while (cin >> ScanInValues[i])
我不想过度编译我的解释,但我只想强调这是执行提取的首选方法。使用!eof()
作为提取的条件几乎总是错误的方式。
相关文章:
- 错误:未在此范围内声明'reverse'
- C++错误C2600:无法定义编译器生成的特殊成员函数(必须首先在类中声明)
- 从具有默认值的部分指定模板类继承时发生SWIG错误,具有不带默认值的正向声明
- 错误:"imread"未在此范围内声明
- 在气泡排序程序中未声明错误功能
- 使用全局声明的向量时,C++双重释放错误/损坏
- 使用直接大括号初始化时,C++ 编译错误"声明末尾的预期";"
- C++ [错误] 声明'char '隐藏参数。什么意思?
- 类中的静态函数给出了错误:声明中的两种或多个数据类型
- 错误:声明冲突 - 指针不能是 int
- 收到 CUDA 错误"声明与以前的"variable_name"不兼容
- 错误:声明不声明
- Visual Studio 2010 链接器错误C++声明我从头文件创建的类时
- Cython 错误:声明不声明任何内容
- 错误"声明非模板函数"C++
- 无效地使用不完整的类型/前向错误声明.可能误用抽象类?(c++)
- 错误:声明冲突.用c++编译c代码
- C++错误:声明中存在显式限定
- else语句(C++)上的错误w/声明
- 初始化const类成员,错误:声明没有声明任何内容