我是一个C++新手.我在这里尝试了我的第一个程序.我的眼睛这个程序是正确的.
#include <iostream>
using namespace std;
class mystruct
{
private:
int m_a;
float m_b;
public:
mystruct(int x, float y)
{
m_a = x;
m_b = y;
}
};
int main()
{
mystruct m = mystruct(5,3.14);
cout << "my structure " << m << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但是我得到了很多错误.不知道为什么?
cout.cpp: In function ‘int main()’:
cout.cpp:26:29: error: no match for ‘operator<<’ in ‘std::operator<< [with _Traits = std::char_traits<char>]((* & std::cout), ((const char*)"my structure ")) << m’
cout.cpp:26:29: note: candidates are:
/usr/include/c++/4.6/ostream:110:7: note: std::basic_ostream<_CharT, …Run Code Online (Sandbox Code Playgroud) 我意识到这个错误通常是由于一些语法或类型问题,但我不知道如何解决这个问题.我认为它可能与findRt的类型有关.
vector<triangle> findRightTriangles(unsigned long l, unsigned long h) {
<triangle> retval; // storage for return value.
triangle t;
double what;
for(t.s1 = 3; t.s1 <= h; t.s1++) {
for(t.s2 = t.s1; t.s2 <= h; t.s2++) {
what = sqrt((t.s1*t.s1) + (t.s2*t.s2));
t.s3 = static_cast<unsigned int>(what);
if(((t.s1*t.s1)+(t.s2*t.s2)) != (t.s3*t.s3)
|| t.s1+t.s2+t.s3 < l
|| t.s1+t.s2+t.s3 > h) {
continue;
}
else if(t.s1+t.s2+t.s3 <= h
&& t.s1+t.s2+t.s3 >= l
&& t.s1+t.s2 > t.s3
&& ((t.s1*t.s1)+(t.s2*t.s2)) == (t.s3*t.s3)) {
retval.push_back(t);
}
}
} …Run Code Online (Sandbox Code Playgroud)