0

我很难弄清楚我的代码中发生了什么。任何帮助将非常感激。这是我的标题(.cuh):

#include <map>
#include <string>
#include <iostream>

#include "SINS_constants.cuh"

using namespace std;

class SINS_inputManager
{
    public:
        static SINS_inputManager& getInstance()
        {
            static SINS_inputManager SINS_inputManager_singleton;
            return SINS_inputManager_singleton;
        }
        void parse(ifstream& cfgfile); // TODO Better read incoming variables, recognize by type in a single loop : template ?

    private:
        static SINS_inputManager* SINS_inputManager_singleton;
        map<string, string> options;

        SINS_inputManager();
        ~SINS_inputManager();
        SINS_inputManager(SINS_inputManager const&);    // not defined copy constructor
        void operator=(SINS_inputManager const&);       // not defined = operator


};

这是我的 .cu :

#include "SINS_inputManager.cuh"

void SINS_inputManager::parse(ifstream& cfgfile)
{
    cout << "\n";

    string id, eq, val;
    while(cfgfile >> id >> eq >> val)
    {
        if (id[0] == '#')
        {
            cfgfile.ignore(numeric_limits<streamsize>::max(), '\n'); // skip comments
            continue;
        }

        if (eq != "=") throw runtime_error("Syntax error in the parser. Each line should follow :\n'unique parameter name' = 'value'\nA commented line begins with a '#' symbol.\n\n");

        options[id] = val;
    }

    istringstream theStream;
    string string_temp;

    theStream.clear();
    theStream.str(options["INITIAL_INPUT"]);
    theStream >> string_temp;
    strcpy(INITIAL_INPUT, string_temp.c_str());

    theStream.clear();
    theStream.str(options["FINAL_OUTPUT"]);
    theStream >> string_temp;
    strcpy(FINAL_OUTPUT, string_temp.c_str());

    theStream.clear();
    theStream.str(options["NB_IONS"]);
    theStream >> NB_IONS;

    theStream.clear();
    theStream.str(options["VERBOSE"]);
    theStream >> VERBOSE;

    theStream.clear();
    theStream.str(options["TIME_MAX"]);
    theStream >> TIME_MAX;

    theStream.clear();
    theStream.str(options["DT_OBS"]);
    theStream >> DT_OBS;

    if(VERBOSE >= 1)
    {
        cout << "The parser has read the following configuration :\n";
        typedef map<string, string>::iterator it_type;
        for(it_type iterator = options.begin(); iterator != options.end(); iterator++)
        {
            cout << "\t" << iterator->first << " = " << iterator->second << "\n";
        }
    }
}

// private constructor
SINS_inputManager::SINS_inputManager()
{

}

// private destructor
SINS_inputManager::~SINS_inputManager()
{

}

这是错误:

/data/pieges/fabian/SINS/code/src/SINS_inputManager.cu(8): error: no operator ">>" matches these operands
            operand types are: std::ifstream >> std::string

/data/pieges/fabian/SINS/code/src/SINS_inputManager.cu(12): error: incomplete type is not allowed

/data/pieges/fabian/SINS/code/src/SINS_inputManager.cu(12): error: identifier "numeric_limits" is undefined

/data/pieges/fabian/SINS/code/src/SINS_inputManager.cu(12): error: type name is not allowed

/data/pieges/fabian/SINS/code/src/SINS_inputManager.cu(12): error: no instance of overloaded function "max" matches the argument list

/data/pieges/fabian/SINS/code/src/SINS_inputManager.cu(16): error: identifier "runtime_error" is undefined

/data/pieges/fabian/SINS/code/src/SINS_inputManager.cu(21): error: incomplete type is not allowed

7 errors detected in the compilation of "/tmp/tmpxft_000076aa_00000000-6_SINS_inputManager.cpp1.ii".
CMake Error at SINS_generated_SINS_inputManager.cu.o.cmake:256 (message):
  Error generating file
  /data/pieges/fabian/SINS/workdir/CMakeFiles/SINS.dir/code/src/./SINS_generated_SINS_inputManager.cu.o


make[2]: *** [CMakeFiles/SINS.dir/code/src/./SINS_generated_SINS_inputManager.cu.o] Erreur 1
make[1]: *** [CMakeFiles/SINS.dir/all] Erreur 2
make: *** [all] Erreur 2

在将文件名更改为 CUDA 扩展名之前,它运行良好。我搜索了谷歌,发现这可能是 string 或 string.h 包含的问题,但我尝试了所有可能的组合但没有成功。我究竟做错了什么 ?

编辑:这是在 .cu 中添加包含和使用命名空间 std 后的新输出:

抱歉,不完全相同的错误(仅适用于字符串):

/data/pieges/fabian/SINS/code/src/SINS_inputManager.cu(14): error: no operator ">>" matches these operands
            operand types are: std::ifstream >> std::string

/data/pieges/fabian/SINS/code/src/SINS_inputManager.cu(18): error: incomplete type is not allowed

/data/pieges/fabian/SINS/code/src/SINS_inputManager.cu(18): error: identifier "numeric_limits" is undefined

/data/pieges/fabian/SINS/code/src/SINS_inputManager.cu(18): error: type name is not allowed

/data/pieges/fabian/SINS/code/src/SINS_inputManager.cu(18): error: no instance of overloaded function "max" matches the argument list

/data/pieges/fabian/SINS/code/src/SINS_inputManager.cu(22): error: identifier "runtime_error" is undefined

/data/pieges/fabian/SINS/code/src/SINS_inputManager.cu(27): error: incomplete type is not allowed

7 errors detected in the compilation of "/tmp/tmpxft_000077e5_00000000-6_SINS_inputManager.cpp1.ii".
CMake Error at SINS_generated_SINS_inputManager.cu.o.cmake:256 (message):
  Error generating file
  /data/pieges/fabian/SINS/workdir/CMakeFiles/SINS.dir/code/src/./SINS_generated_SINS_inputManager.cu.o


make[2]: *** [CMakeFiles/SINS.dir/code/src/./SINS_generated_SINS_inputManager.cu.o]

错误 1 ​​制作 [1]:* [CMakeFiles/SINS.dir/all] 错误 2 制作:* [全部] 错误 2

4

2 回答 2

0

将下一个标头添加到 .cu 文件:

#include <fstream>
#include <limits>
#include <stdexcept>
于 2013-10-03T17:13:58.790 回答
0

尝试将这些行从 .cuh 移动到 .cu 文件中

#include <map>
#include <string>
#include <iostream>
using namespace std;

尤其是这条线using namespace std;

于 2013-10-03T16:05:18.883 回答