C++ "not declared in this scope"错误
c++ "not declared in this scope" error
我一直收到一个错误,告诉我没有在if(!buffer.empty)循环下的作用域中定义缓冲区。
有人对我应该做什么和我做错了什么有什么建议吗?
#include <fstream> // this is to import the ifstream and ofstream objects
#include <iostream> // this is to import the cin and cout objects
#include <stack>
using namespace std;
// precondition: theFile refers to a stream that has been opened already
// postcondition: the contents of the file have been read and output to the console
void read_file( ifstream& theFile ) {
stack buffer; // this string will read in the buffer from the file
//while there are still things in the file to read in, read it in and output to console.
while( theFile.eof() == false ) {
buffer.push(theFile);
//cout << buffer << endl; // print the string and a newline
}
if( !buffer.empty() ) {
cout << buffer.top() << endl;
buffer.pop();
}else{
cout << "uh oh!" << endl;
}
}
int main() {
ifstream theInputFile;
theInputFile.open("input.txt"); // Open the file with the name "inputFile.txt".
// pass the file stream into the read_file() function.
read_file( theInputFile );
theInputFile.close();
}
所以缓冲区是一个堆栈。堆什么?stack<int> buffer
可以工作,或者stack<char> buffer
,或者你需要的任何东西。
我不知道你需要一堆什么。我注意到你在推theFile
,这没有意义。这可能是有道理的:
while( theFile.eof() == false )
{
theFile >> something;
if (! theFile) break; //if we reached eof or had other problems, just quit
buffer.push(something);
}
如果something
是char, char*
或string
,则取决于要对空白进行什么处理。
相关文章:
- 类中的数组变量C++导致"was not declared in this scope"实现文件的一个函数中错误,但在构造函数中不会导致错误
- 如何解决"cout was not declared in this scope"错误?
- 为什么我会收到"getuid was not declared in that scope"错误?
- 即使包含 <time.h 后仍"‘CLOCK_PER_SEC’ was not declared in this scope"错误>
- python boost scope 会导致 NoneType 错误
- 在C++中出现"scope"错误
- 如何从类调用函数 - 错误"was not in the scope"
- main.cpp中的错误:函数库中的函数"not declared in this scope",但实际上是
- 尝试解决"out of scope"编译错误:CodeBlocks,Linux Fedora
- " 'X' not declared in this scope "错误
- 包含 Windows.h 和 wingdi.h 时出现"GradientFill was not declared in this scope"错误
- OpenCV C++ "CvSURFParams was not declared in this scope"错误
- 安卓 JNI C++中的"Not declared in this scope"错误
- 非平凡的"Not declared in this scope"错误
- 包含模板的头文件中"not declared in scope"错误
- C++ "not declared in this scope"错误
- 实现哈希表,插入函数导致"scope"错误
- "Was not declared in this scope"错误结构定义。C++
- 模板和继承"not declared in this scope"错误
- C++。与代码相关::块 IDE。"object is not declared in this scope"错误