Question: The code typed : void CarSimulator::ReadCommandsFromFile(){ ifstream myfile (_inputFileName); if (myfile.is_open()) { string myLine; double vel, angle, timeStamp; Command c; while ( getline (myfile,myLine) )

 The code typed : void CarSimulator::ReadCommandsFromFile(){ ifstream myfile (_inputFileName); if (myfile.is_open())

The code typed :

void CarSimulator::ReadCommandsFromFile(){

ifstream myfile (_inputFileName);

if (myfile.is_open())

{

string myLine;

double vel, angle, timeStamp;

Command c;

while ( getline (myfile,myLine) )

{

sscanf(myLine.c_str(), "%lf %lf %lf", &vel, &angle, &timeStamp);

c.SetVelocity(vel);

c.SetTireAngleRate(angle);

c.SetTimeStamp(timeStamp);

if(c.IsValid()){

_commands.push_back(c);

}

else{

// clear command vector

return ;

}

}

myfile.close();

}

}

so im running it on a bash terminal and it appears to be not reading my txt files .

as it can be seen on this pic below:

{ string myLine; double vel, angle, timeStamp; Command c; while ( getline

and just one last thing how could i convert this line of code to C ++ :

sscanf(myLine.c_str(), "%lf %lf %lf", &vel, &angle, &timeStamp);

ceause on my assignment everything should be a C ++ syntax.

this is the code i got sofar so please help me getting the files being read correct my code and change the sscanf(myLine.c_str(), "%lf %lf %lf", &vel, &angle, &timeStamp); to a C ++

23 24 25 Populates object_commands data member frominputFileName 26 27 Orequirement if the Command IsValid) returns false for any Command, the input file is invalidated. An output file still needs to be generated 28 Orequirement if a line is not formatted correctly, the file is not invalidated. It is just discarded 29 Orequirement close the file at the end of the function 30 31 void CarSimulator: : ReadCommands FromFile) ifstream myfile (inputFileName); if (myfile.is open()) 35 string myLine; double vel, angle, timeStamp; Command ci while getline (myfile, myLine)) 37 38 sscanf(rmy Line . c-str(), "%1f %1f %1f", &vel, &angle, &timeStamp); 40 41 c.SetVelocity(vel); c.SetTireAngleRate (angle); c.SetTimeStamp (timeStamp); if(c.IsValid)) commands.push_back(c); 47 elset // clear command vector 51 52 return myfile.close) 56 57 58 23 24 25 Populates object_commands data member frominputFileName 26 27 Orequirement if the Command IsValid) returns false for any Command, the input file is invalidated. An output file still needs to be generated 28 Orequirement if a line is not formatted correctly, the file is not invalidated. It is just discarded 29 Orequirement close the file at the end of the function 30 31 void CarSimulator: : ReadCommands FromFile) ifstream myfile (inputFileName); if (myfile.is open()) 35 string myLine; double vel, angle, timeStamp; Command ci while getline (myfile, myLine)) 37 38 sscanf(rmy Line . c-str(), "%1f %1f %1f", &vel, &angle, &timeStamp); 40 41 c.SetVelocity(vel); c.SetTireAngleRate (angle); c.SetTimeStamp (timeStamp); if(c.IsValid)) commands.push_back(c); 47 elset // clear command vector 51 52 return myfile.close) 56 57 58

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!