안녕하세요 누구든지 도와 줄 수 있습니까? 개체 스택 (이 경우 포인트)의 맨 위 요소를 인쇄해야하고 온라인에서 솔루션을 찾을 수 없습니다. 나는 cout에서 pointStack.top()을 호출하는 최상위 또는 직선의 데이터 유형을 변경하려고 시도했지만 아무런 운이 없었습니다. 노트. 오류 C2679 문제 귀하의 설명에 따르면OOP C++를 사용하여 스택 항목을 인쇄 할 수 없습니다
#include <iostream>
#include <stack>
#include "point.h"
using namespace std;
int main(){
stack<Point> pointStack;
Point p;
int i;
int counter = 0;
for (i = 0; i < 10; i++){
p.pCreate();
Point p1(p.getXPos(), p.getYPos());
pointStack.push(p1);
counter++;
}
while (!pointStack.empty()){
Point top = pointStack.top();
cout << top; // error C2679
cout << pointStack.top(); // also error C2679
}
system("PAUSE");
return 0;
}
#ifndef __Point__
#define __Point__
using namespace std;
class Point{
private:
int x, y;
public:
Point();
Point(int x, int y);
int getYPos(){ return y; }
int getXPos(){ return x; }
void pCreate();
};
#endif
Point::Point(){
x = 0, y = 0;
}
Point::Point(int a, int b){
x = a;
y = b;
}
void Point::pCreate(){
x = -50 + rand() % 100;
y = -50 + rand() % 100;
}
[MCVE] (https://stackoverflow.com/help/mcve)를 제공하면 좋을 것입니다. 당신은 "point.h"를 보여주지 않았다. – javaLover
[오류 C2679 : 바이너리 '<<': 연산자 없음] (http://stackoverflow.com/questions/22724064/error-c2679-binary-no-operator-found-which-takes-a-right-hand- operand-of)도 도움이 될 수 있습니다. – javaLover
좋습니다. 아주 기본이지만 수행 할 것입니다. –