Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/155.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 未定义对“readVector(std::u cxx11::basic_string<;char,std::char_traits<;char>;,std::allocator<;char>;)和&x27;的引用;_C++_C++11 - Fatal编程技术网

C++ 未定义对“readVector(std::u cxx11::basic_string<;char,std::char_traits<;char>;,std::allocator<;char>;)和&x27;的引用;

C++ 未定义对“readVector(std::u cxx11::basic_string<;char,std::char_traits<;char>;,std::allocator<;char>;)和&x27;的引用;,c++,c++11,C++,C++11,当我试图编译代码时,收到了以下错误消息: c++-Ofast-march=native-DNDEBUG-std=c++11-Wc++11扩展-Wall matvec.o amath483.o Vector.o-o matvec matvec.o:在函数main:中:matvec.cpp:(.text+0x209):对readVector的未定义引用(std::_ucx11::basic_string,std::allocator>)'clang:错误:链接器命令失败,退出代码为1(使用-v查看调

当我试图编译代码时,收到了以下错误消息:

c++-Ofast-march=native-DNDEBUG-std=c++11-Wc++11扩展-Wall matvec.o amath483.o Vector.o-o matvec

matvec.o:在函数
main:中:matvec.cpp:(.text+0x209):对
readVector的未定义引用(std::_ucx11::basic_string,std::allocator>)'clang:错误:链接器命令失败,退出代码为1(使用-v查看调用)makefile:5:目标'matvec'的配方失败make:**[matvec]错误1

我的代码如下:

#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <fstream>
#include "Vector.hpp"

using namespace std;


Vector readVector(istream& input) {
    string string_input;
    int n;
    getline(input,string_input);
    if(string_input.compare("AMATH 583 VECTOR") != 0) exit(-1);
    input >> n;
    Vector v(n);
    for(int i = 0; i < n; i++)
        input >> v(i);
    getline(input,string_input);
    getline(input,string_input);

    if(string_input.compare("THIS IS THE END") != 0) exit(-1);

    return v;
}


Vector readVector(ifstream& file) {
    string string_input;
    int n;
    getline(file,string_input);
    if(string_input.compare("AMATH 583 VECTOR") != 0) exit(-1);
    file >> n;
    Vector v(n);
    for(int i = 0; i < n; i++)
        file >> v(i);
    getline(file,string_input);
    getline(file,string_input);

    if(string_input.compare("THIS IS THE END") != 0) exit(-1);

    return v;
}

#include "Vector.hpp"
#include <iostream>
#include <fstream>
#include "amath483.hpp"

using namespace std;

int main(int argc, char* argv[]) {
    if(argc < 2 || argc > 4) {
        cout << "You must provide at least one argument or at most three arguments(including two options)" << endl;
        return -1;
  }

    int inputoption = -1;
    int outputoption = -1;
    if(argc == 3) {
        inputoption = 0;
    }
    if(argc == 4) {
        inputoption = 0;
        outputoption = 0;
    }

    // Check the format
    Vector v = NULL;
    if(inputoption == 0) {
        string inputfile = argv[2];
        v = readVector(inputfile);
    } else {
        v = readVector(cin);
    }

    for(int i=0; i < v.numRows(); i++)
        cout << v(i) << endl;
    return 0;
}
#包括
#包括
#包括
#包括
#包括
#包括“Vector.hpp”
使用名称空间std;
矢量读取矢量(istream&input){
字符串输入;
int n;
getline(输入,字符串输入);
如果(字符串输入比较(“AMATH 583向量”)!=0)退出(-1);
输入>>n;
向量v(n);
对于(int i=0;i>v(i);
getline(输入,字符串输入);
getline(输入,字符串输入);
如果(string_input.compare(“到此结束”)!=0)退出(-1);
返回v;
}
矢量读取矢量(ifstream和文件){
字符串输入;
int n;
getline(文件、字符串和输入);
如果(字符串输入比较(“AMATH 583向量”)!=0)退出(-1);
文件>>n;
向量v(n);
对于(int i=0;i>v(i);
getline(文件、字符串和输入);
getline(文件、字符串和输入);
如果(string_input.compare(“到此结束”)!=0)退出(-1);
返回v;
}
#包括“Vector.hpp”
#包括
#包括
#包括“amath483.hpp”
使用名称空间std;
int main(int argc,char*argv[]){
如果(argc<2 | | argc>4){

显然您的输入类型是错误的:
std::string inputfile
不是
std::ifstream
std::istream
。您需要打开一个输入
std::ifstream
文件,其名称存储在
inputfile
中,然后将其传递给
readVector

,在代码中您没有显示的某个地方,您有一个decl使用
std::string
参数的
readVector
操作。这是您实际使用
readVector(inputfile)
调用的重载,但您尚未实现它。显然,您的输入类型错误:
std::string inputfile
不是
std::ifstream
std::istream