小编Ogh*_*ris的帖子

为什么我收到ifstream错误?

Implicit instantiation of undefined template 'std::basic_ifstream<char,std::char_traits<char>>'


#ifndef MAPPER_H
#define MAPPER_H
#include <iostream>
#include <string>
#include <vector>
#include "KeyValue.h"
#include "Parser.h"

using namespace std;
class Mapper
{
public:
    Mapper(ifstream& infile);
    ~Mapper(void);
    void loadTokens();
    void showTokens();
    void map();
    void printMap();
    void printMap(string map_fileName);
private:
    ifstream inFile;  //<-- is where the error is happening
    vector<string> tokens;
    vector<KeyValue> map_output;
    Parser* parser;
};

#endif
Run Code Online (Sandbox Code Playgroud)

我甚至尝试过推杆std::ifstream但它仍然无效.

当我#include <fstream>代替的#include <iostream>,我在得到这些错误fstream.tccbasic_ios.tcc:

'operator=' is a private member of 'std::basic_streambuf<char>' …

c++ fstream compiler-errors ifstream

38
推荐指数
1
解决办法
3万
查看次数

XCode上的C++ ifstream:默认目录在哪里?

好吧,这是我第一次在Xcode中编写C++(我习惯于ObjC),现在我已经开始在我的大学开设编程课程.

我正在尝试打开一个文件(硬编码或来自控制台中的用户输入),无论我尝试什么,它都说文件无法打开(通过错误检查)

我假设它是因为我所拥有的test.txt文件不在假定的根目录中,所以如果是这样的话,根目录是什么?

到目前为止,这是我的代码:

//include files
#include <iostream>
#include <stdio.h>
#include <fstream>

using namespace std;

//Global Variables
short inputPicture[512][512];
short outputPicture[512][512];

//Function Prototypes
void getInput(char* in, char* out);
void initializeArray(ifstream* input);

//Main
int main(){
    //local variables
    char inputFile[32];
    char outputFile[32];

    ifstream input;
    ofstream output;


    getInput(inputFile, outputFile);
    cout << inputFile << endl;//test what was sent back from the function

    input.open(inputFile, ifstream::in);
    if (!input.is_open()){//check to see if the file exists
        cout << "File not found!\n";
        return 1;//if not found, end program
    } …
Run Code Online (Sandbox Code Playgroud)

c++ ifstream

5
推荐指数
2
解决办法
2万
查看次数

错误:"预期的班级名称"

我在这里搜索了其他"预期的类名"错误问题,但它们都是"......之前'{'标记'或"......之前';'".

解决方案是包含正确的文件,但我的文件包含包含继承类的.h文件.

#include "BinaryNode.h"
#include "bst.h"

template <class T>
class SOBTree: public BinarySearchTree { //Expected Class Name
public:
    void insert( const T& x );
    void remove( const T& x );
    int reportComparisonCount();
    double reportCPUTime();


private:
    void insert( const T & x, BinaryNode<T> * & t );
    void RotateRight(BinaryNode<T> * & root );
    void RotateLeft(BinaryNode<T> * & root );
    BinaryNode<T> *root;

};
Run Code Online (Sandbox Code Playgroud)

继承的类在bst.h中定义,因此我没有其他文件包含在项目中.

很抱歉这个简单的问题,我只是不知道为什么会发生错误.

c++ inheritance class

1
推荐指数
1
解决办法
2320
查看次数

标签 统计

c++ ×3

ifstream ×2

class ×1

compiler-errors ×1

fstream ×1

inheritance ×1