Dec 9, 2012 at 9:19pm UTC
regarding the code
1 2 3 4 5 6 7
while ( ss >> Action >> value )
{
if ( string("REPEAT" ) == Action )
{
cout << "\nNew row : (REPEAT," << value << ") " ;
nRepeats.push_back(value);
CommandList.push_back( std::string () );
the instruction is this
REPEAT 36 [ RIGHT 10 REPEAT 360 [ FORWARD .04 RIGHT 1 ] ]
without brackets its
REPEAT 36 RIGHT 10 REPEAT 360 FORWARD .04 RIGHT 1
so it only detects REPEAT 36 and exits the loop.
also if i change it to
REPEAT 36[RIGHT 10 REPEAT 360[FORWARD .04 RIGHT 1 ]]
becomes without bracket
REPEAT 36 RIGHT 10 REPEAT 360 FORWARD .04 RIGHT 1
and when i loop through the code and it comes to RIGHT
when it prints it displays
(REPEAT,36) ([RIGHT,10)
how did that square bracket get there.
Last edited on Dec 9, 2012 at 9:39pm UTC
Dec 9, 2012 at 11:02pm UTC
That could be because you didn't remove the brackets.
Dec 10, 2012 at 12:50am UTC
i did i used this
replace(cmd.begin(), cmd.end(), '[', ' ');
replace(cmd.begin(), cmd.end(), ']', ' ');
before the while loop
Dec 10, 2012 at 3:38am UTC
i am trying to send amount value to a class and have done the following:
global variable
vector<string> actvec;
vector<float> amountvec;
class Commands
{
public:
Commands();
virtual ~Commands();
virtual void performaction(){};
protected:
float amount;
};
class Forward : public Commands
{
public:
void performaction()
{
actvec.push_back("FORWARD");
amountvec.push_back(amount);
}
};
same with other commands, as that is what is required from me, to set a class for each one that inherits from the main base class.
void performcommand(string commandstr, float amnt)
{
if(commandstr=="LEFT")
{
Left.amount=amnt;
Left.performaction();
}
else if(commandstr=="RIGHT")
{
Right.amount=(-amnt);
Right.performaction();
}
else if(commandstr=="FORWARD")
{
Forward.amount=amnt;
Forward.performaction());
}
else if(commandstr=="JUMP")
{
Jump.amount=amnt;
Jump.performaction();
}
else cout<<"The Command was not identifiable"<<endl;
}
but for each line it says expected unqualified-id before '.' token
i don't understand
Last edited on Dec 10, 2012 at 3:40am UTC
Dec 10, 2012 at 9:10am UTC
would you mind looking at my complete code and tell me where i am going wrong as there might be mistakes in other areas.
regards
Dec 10, 2012 at 5:41pm UTC
ok i am making some progress
my program draws commands that don't contain repeat commands but the ones contain repeat commands it causes a segmentation fault.
Dec 10, 2012 at 6:42pm UTC
THe main error i am getting is during the following code
while( as >> action >> value )
{
as << action << ' ' << value << ' ';
tempcomd.push_back(as.str());
cout<<action<<","<<value<<endl;
}
it just goes through this forever
forward 0.04
right 1
forward 0.04
right 1
and so on.
Last edited on Dec 10, 2012 at 6:59pm UTC
Dec 10, 2012 at 7:27pm UTC
i have solved that as well
i placed it in a loop it would work outside and eureka it works
Dec 10, 2012 at 8:45pm UTC
the project is finally finished and all works well
thanks for the help
Dec 12, 2012 at 4:37pm UTC
just one more thing
since i am moving over to linux to test this on.
i have added error code if it can't find file, which when i run i get that error,
linux doesn't have c:\ it does it straight from root so when i place
ifstream myfile ("\\home\\C++Project\\command.txt") it still says can't find file.
how can i write it so i just do istream myfile("command.txt");
because even when i write that it says file not found on current directory
my error message
thanks
Dec 13, 2012 at 1:36pm UTC
It works now, i just
added chdir to the project directory and then it would find it
strange, wonder directory it was previously looking at in linux.