C++ 写入文件c+的语法+; 类状态{ 私人: double _timestamp;//测量此状态的时间戳 双_xpos;//车辆位置,向前(x1) 双_ypos;//车辆位置,左/右(x2) 双_轮胎_角度;//轮胎角度(弧度)(x3) 双_航

C++ 写入文件c+的语法+; 类状态{ 私人: double _timestamp;//测量此状态的时间戳 双_xpos;//车辆位置,向前(x1) 双_ypos;//车辆位置,左/右(x2) 双_轮胎_角度;//轮胎角度(弧度)(x3) 双_航,c++,io,fstream,C++,Io,Fstream,写入文件c+的语法+; 类状态{ 私人: double _timestamp;//测量此状态的时间戳 双_xpos;//车辆位置,向前(x1) 双_ypos;//车辆位置,左/右(x2) 双_轮胎_角度;//轮胎角度(弧度)(x3) 双_航向;//航向(弧度)(x4) 公众: //使用这些初始值构造一个新的状态对象 状态(双x1、双x2、双x3、双x4、双时间戳); //构造空状态对象 状态(); double getXPos()const;//返回_xpos void setX

写入文件c+的语法+;
类状态{
私人:
double _timestamp;//测量此状态的时间戳
双_xpos;//车辆位置,向前(x1)
双_ypos;//车辆位置,左/右(x2)
双_轮胎_角度;//轮胎角度(弧度)(x3)
双_航向;//航向(弧度)(x4)
公众:
//使用这些初始值构造一个新的状态对象
状态(双x1、双x2、双x3、双x4、双时间戳);
//构造空状态对象
状态();
double getXPos()const;//返回_xpos
void setXPos(double xpos);//设置_xpos
double getYPos()const;//返回_ypos
void setYPos(double ypos);//设置_ypos
double gettirelange()const;//返回_轮胎_角度
void setTireAngle(双角度);//设置_轮胎_角度
double getHeading()const;//获取_标题
void setHeading(双标题);//设置_标题
double getTimeStamp()const;//获取_时间戳
void setTimeStamp(双时间戳);//设置_时间戳
};
类数据链路{
私人:
矢量汇;
公众:
无效设置链接(状态x);
无效打印接收器(字符*文件名);
}; 
void DataSink::printSink(字符*文件名){
int i;
出流孔的直径;
outFile.open(文件名);
如果(!outFile.is_open())
{

您是否尝试过将所有内容写入std::cout
?我在.cpp的顶部定义了名称空间std。sink的声明在哪里?放置调试所需的所有代码添加了相关内容。
class State{
private:
    double _timestamp; // time stamp at which this state is measured
    double _xpos; // vehicle position, forward (x1)
    double _ypos; // vehicle position, left/right (x2)
    double _tire_angle; // tire angle (radians) (x3)
    double _heading; // heading (radians) (x4)

public:
     // constructs a new State object with these initial values
     State(double x1, double x2, double x3, double x4, double timestamp);
     // constructs an empty State object
     State();

     double getXPos() const; // returns the _xpos
     void setXPos(double xpos); // sets the _xpos
     double getYPos() const; // returns the _ypos
     void setYPos(double ypos); // sets the _ypos
     double getTireAngle() const; // returns the _tire_angle
     void setTireAngle(double angle); // sets the _tire_angle
     double getHeading() const; // gets the _heading
     void setHeading(double heading); // sets the _heading
     double getTimeStamp() const; // gets the _timestamp
     void setTimeStamp(double timestamp); // sets the _timestamp
};


class DataSink{
private:
    vector<State> sink;
public:
    void setSink(State x);
    void printSink(char* fileName);
}; 

void DataSink::printSink(char* fileName){
    int i;
    ofstream outFile;

    outFile.open(fileName);

    if (!outFile.is_open())
    {
        cout << "Could not open file " << fileName << endl;
        return;
     }

    for (i = 0; i < sink.size(); ++i)
    {
        outFile << sink.at(i).getXPos() << "," << sink.at(i).getYPos()<< "," << sink.at(i).getTireAngle()<< "," << sink.at(i).getHeading()<< "," << sink.at(i).getTimeStamp() << endl;
    }

    outFile << "Test.\n";

    outFile.close();

    return;
 }