Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7942423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:57:56+00:00 2026-06-03T23:57:56+00:00

I’m working on a bit of code for my C++ class, and I’m a

  • 0

I’m working on a bit of code for my C++ class, and I’m a bit stuck.

Here’s the bit of the assignment I’m working on:


Within the Rover class, specify the following member instance variables:

 name (String)

 x position on a grid (integer)

 y position on a grid (integer)

 direction by compass – N, S, E, or W (String)

 speed (0 – 5 meters per second, integer)

Within the Rover class, specify the following methods:

 No-arg constructor – set the rover’s position to (0,0), its speed to 0, 
  its direction to North,and its name to Default

 Constructor that receives parameters to initialize all five 
  instance variables described above

 Setter methods for each instance variable

 Getter methods for each instance variable

 getRoverData – returns a string that displays values for each instance 
  variable of the current rover object, placing each value on a separate line, 
  as follows:

So right now I just want to get the base case to work. Here’s the entirety of my code:


main.cpp:

#include <iostream>
#include "Rover.h"

using namespace std;


int main() {

    Rover rover1;

    rover1.setDefaultValues();

    cout<<rover1.getRoverData(rover1)<<endl;

    return 0;
}

rover.cpp:

#include <iostream>
#include "Rover.h"
using namespace std;

//put functions in here

void Rover::setDefaultValues() {
    name = "Default";
    xcoord = 0;
    ycoord = 0;
    direction = "N";
    speed = 0;

}

void Rover::constructRover() {

}

void Rover::setXcoord(int xcoord) {
    this->xcoord = xcoord;
}

void Rover::setYcoord(int ycoord) {
    this->ycoord = ycoord;

}

void Rover::setName(string name) {
    this->name = name;
}

void Rover::setDirection(string direction) {
    this->direction = direction;
}

void Rover::setSpeed(int speed) {
    this->speed = speed;
}

int Rover::getXcoord() {
    return xcoord;

}

int Rover::getYcoord() {
    return ycoord;
}

string Rover::getName() {
    return name;
}

string Rover::getDirection() {
    return direction;
}

int Rover::getSpeed() {
    return speed;
}

string Rover::getRoverData(Rover rover) {
    string printStatement = "";
    printStatement.append("Data for " << rover.getName());
    printStatement.append("\nX: " << Rover::xcoord);
    printStatement.append("\nY: " << Rover::ycoord);
    printStatement.append("\nDirection: " << Rover::direction);
    printStatement.append("\nSpeed: " << Rover::speed);
    return printStatement;

}

Rover.h:

/* 
 * File:   Rover.h
 * Author: Matthew
 *
 * Created on May 14, 2012, 8:10 PM
 */


#ifndef ROVER_H
#define ROVER_H

using namespace std;


class Rover
{
        private:
            string name;
            int xcoord;
            int ycoord;
            string direction;
            int speed;


    public:
            void setDefaultValues();
            void constructRover();
            //XCoordinates
            void setXcoord(int xcoord);
            int getXcoord();
            //YCoordinates
            void setYcoord(int ycoord);
            int getYcoord();
            //Name
            void setName(string name);
            string getName();
            //Direction
            void setDirection(string direction);
            string getDirection();
            //Speed
            void setSpeed(int speed);
            int getSpeed();
            //Printout
            string getRoverData(Rover rover);

};

#endif  /* ROVER_H */

The error I’m currently getting is:

rover.cpp:64: error: no match for 'operator<<' in '"Data for " << Rover::getName()()'

The heck does that mean?

At this point, what I want the printout to say is:

Data for Default
X: 0
Y: 0
Direction: N
Speed: 0

Any thoughts?

Sorry if the code looks awful as I posted it…haven’t done this before.


UPDATE:


#include <iostream>
#include "Rover.h"
using namespace std;

//put functions in here

void Rover::setDefaultValues() {
    name = "Default";
    xcoord = 0;
    ycoord = 0;
    direction = "N";
    speed = 0;

}

void Rover::constructRover() {

}

void Rover::setXcoord(int xcoord) {
    this->xcoord = xcoord;
}

void Rover::setYcoord(int ycoord) {
    this->ycoord = ycoord;

}

void Rover::setName(string name) {
    this->name = name;
}

void Rover::setDirection(string direction) {
    this->direction = direction;
}

void Rover::setSpeed(int speed) {
    this->speed = speed;
}

int Rover::getXcoord() {
    return xcoord;

}

int Rover::getYcoord() {
    return ycoord;
}

string Rover::getName() {
    return name;
}

string Rover::getDirection() {
    return direction;
}

int Rover::getSpeed() {
    return speed;
}

string Rover::getRoverData(Rover rover) {
    string printStatement = "";
    printStatement.append("Data for " + rover.getName());
    printStatement.append("\nX: " + rover.getXcoord());
    printStatement.append("\nY: " + rover.getYcoord());
    printStatement.append("\nDirection: " + rover.getDirection());
    printStatement.append("\nSpeed: " + rover.getSpeed());
    return printStatement;

}

So, now the printout is:

Data for Default
X:
Y:
Direction: N
Speed:

So, it basically just won’t print out the zeroes. Thoughts?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T23:57:58+00:00Added an answer on June 3, 2026 at 11:57 pm

    The << is the stream insertion operator. There is no function anywhere that takes a const char[] left hand side and a std::string right hand side. Therefore, you’re getting errors.

    You may use this combination when using cout, but it’s a bit deceptive. A call of:

    std::cout << "Some string" << someStdString;
    

    Is defined as:

    (std::cout << "Some string") <<  someStdString;
    

    The actual call is equivalent to:

    operator<< (operator<< (std::cout, "Some string"), someStdString);
    

    The thing that makes it work is that the inside call returns the same cout is was passed in so that it can be used with the other call. If you don’t use something like cout that exhibits this behaviour, it won’t work the same way. This is also why you can say:

    int i = 5 + 2 + 3;
    

    The 5 + 2 returns an int, which is added with 3, and that returns the int assigned to i.

    To concatenate the string inside, you can just replace that with a plus, since addition for strings and char arrays is defined as part of std::string, or add another append call:

    printStatement.append("Data for " + rover.getName());
    //or
    printStatement.append("Data for ");
    printStatement.append(rover.getName());
    //or
    printStatement += "Data for " + rover.getName();
    

    Update:

    To answer your other inquiry, this is another feature of C++ that isn’t part of Java. I didn’t realize you were adding ints onto some of them. When you do that, the character array in the quotes actually decays into a pointer. Then, pointer arithmetic is used to add the integer. Not what you wanted at all. So basically you’re passing in the pointer to the beginning of the string literal, moved forward x characters, where x is the number you’re adding to it. Adding 0 means it just stays there, so the whole string is passed and the + 0 is pretty much dead code.

    If you’re going to be adding ints on, you need a way to convert the integers to strings, and then add them on. C++11 has stoi, but that’s the opposite of what you want. Instead, you can use a stringstream, among other methods:

    #include <sstream>
    
    int main()
    {
        std::stringstream ss;
        ss << 5; //the int to be converted
        std::string s = ss.str(); //get the string
        cout << s + " is the number"; //print with an added string
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have this code to decode numeric html entities to the UTF8 equivalent character.
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm parsing an XML file, the creators of it stuck in a bunch social

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.