C2280运行程序时出错

时间:2016-07-30 04:52:46

标签: c++

我运行程序后遇到了错误c2280,我无法确定问题出在哪里。有人会就这个问题向我提出建议吗?     transaction.h     #ifndef TRANSACTION_H     #define TRANSACTION_H

#include <iostream>
#include <string>
#include <sstream>
#include <cstring>


using namespace std;

class Transaction
{
public:
    Transaction(string input);
    string getDate();
    string getTime();
    string getCondition();
    float getPrice();
    float getValue();
    int getVolume();
    void find_and_replace(string& source, string const& find, string const& replace);

private:
    ostringstream date;
    ostringstream time;
    string condition;
    float price, value;
    int volume, day, month, year, hour, minute;
};

Transaction::Transaction(string input) {

    find_and_replace(input, "/", " ");
    find_and_replace(input, ":", " ");
    find_and_replace(input, "", " ");
    stringstream tranStream(input);
    tranStream >> day;
    tranStream >> month;
    tranStream >> year;
    tranStream >> hour;
    tranStream >> minute;
    tranStream >> price;
    tranStream >> volume;
    tranStream >> value;
    tranStream >> condition;

}

string Transaction::getDate() {
    date << day << '/' << month << '/' << year;

    return date.str();
}

string Transaction::getTime() {
    string PlusZero;
    if (minute < 10) {
        PlusZero = "" + to_string(minute);
        time << hour << ':' << PlusZero;
    }
    else {

        time << hour << ':' << minute;
    }
    return time.str();
}

float Transaction::getPrice() {
    return price;
}

int Transaction::getVolume() {
    return volume;
 }

float Transaction::getValue() {
    return value;
}

string Transaction::getCondition() {
    return condition;

}

void Transaction::find_and_replace(string& source, string const& find, string const& replace)
{
    for (string::size_type i = 0; (i = source.find(find, i)) != string::npos;)
    {
        source.replace(i, find.length(), replace);
        i += replace.length();
    }
}

#endif // !TRANSACTION_H

mainmenu.cpp
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include "Transaction.h"

using namespace std;

void printStock(vector<Transaction> t, int i) {
    cout << "Date :" << t.at(i).getDate << endl;
    cout << "Time :" << t.at(i).getTime() << endl;
    cout << "Price : " << t.at(i).getPrice() << endl;
    cout << "Volume : " << t.at(i).getVolume() << endl;
    cout << "Value : " << t.at(i).getValue() << endl;
    cout << "Condition: " << t.at(i).getCondition() << endl;
    cout << endl;
}


int main() {
    string menu;

    vector<Transaction> TransList;
    string a = "24/07/2015 17:00,6,67889,407334,CT";
    string b = "24/07/2015 17:01,5.8,144,835.2,XT";
    string c = "24/07/2015 17:04,0,0,0,CTXT";
    string d = "24/07/2015 17:10,5.78,1203,6953.34,CT";

    TransList.push_back(a);
    TransList.push_back(b);
    TransList.push_back(c);
    TransList.push_back(d);



    for (int i = 0; i < TransList.size(); i++) {
    printStock(TransList, i);
    }

    cin >> menu;
    return 0;
}

我怀疑它是向量的问题,因为当我禁用向量并检查每个字符串的结果时,这个问题并没有出现。 但我需要一个向量来存储读取的数据以用于解析目的。 谢谢大家!

1 个答案:

答案 0 :(得分:0)

dragView不允许复制,并且您的班级内部有两次,因此如果没有自己的复制构造函数,则无法复制此类。但是你可以改变: ostringstreamvoid printStock(vector<Transaction> t, int i) { 并通过引用传递矢量而不是复制。

也许考虑使用void printStock(vector<Transaction> & t, int i) {代替emplace_back直接在vector中构造Transaction。使用push_back创建临时对象,然后使用移动构造函数将其添加到向量中。

另一个错误在于: push_back它应该是getDate()而不仅仅是getDate