English 中文(简体)
c ++ 帮助阅读,从小到尾。 操作员超载
原标题:c++ Help with reading in from stdin and to stdout . Also Operator overloading

在法典的这一部分,我需要帮助...... 我本应两倍于施莫。 如果我喜欢“Schmoo(8.0,9.0)”的话,那么它就会发现,但当我尝试时,我会发现错误。 我认为,我正在弄清两点错误,如何妥善从cin中提取每件东西。 只要是投入,我就需要继续这样做。

 while(cin){
    string command1 = "add schmoo";
    string input;
    cin >> input;
    double a,b;
    if(input == command1){
      cin >> a >> b;
      Schmoo *a = new Schmoo(a,b);
      c.insertFront(a);
    }
    string command2 = "throw mud";

    if(input == command2){
      cin >> a >> b;
      c.throwMudAt(a,b);
    }

还需要帮助超负荷使用这一机会:

ostream &operator<<(ostream &os, Schmoo &s){
  if(s.getMud() == 1){
    os << "Schmoo at (" << s.x << ", " << s.y << ") was hit mud " << mud << "time.";
  }
  os << "Schmoo at (" << s.x << ", " << s.y << ") was hit with mud" << mud << "times.";
  return os;
}

我正在经历一个错误,必须做的是s.getMud(a);我已经用过的是过了泥土,然后是一位前线人,但这个类别与任何有点人的朋友都没有关系。 但是, Mud是同一类别的职能,我如何使用Mud();在这方面。

问题回答

。 或者将指挥改为“再造”。


对于您的超载,如何界定“<代码>Schmoo?

Your problem is coming primarily from this line:

string input;
cin >> input;

如果你的输入是add schmoo 8.0 9.0,那么cin >>put就不会奏效,因为你没有确切地表明何时应当停止读写。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签