C++ unable to call std::endl

Framed the question better manner: Have a logger C++ class which has the << operator overloaded to accept ints, strings.. logR <<"Test"<<endl Now the endl had been defined as macro #define endl "nr" Now in any .cpp file if i included this logger class's header file i used to get compilation error for using endl. Found a fix for this instead of defining macro endl, I

C ++无法调用std :: endl

改善问题的框架: 有一个记录器C ++类,其中<<操作符被重载以接受整数,字符串.. logR <<"Test"<<endl 现在,endl被定义为宏 #define endl "nr" 现在在任何.cpp文件中,如果我包含此记录器类的头文件,我曾使用endl编译错误。 找到了一个解决方案,而不是定义宏endl,我重载运算符来接收endl()本身。 感谢您帮助解决问题的投入。 从标准N4687: 20.5.4.3.2宏名称 1包含标准库头的翻译单元不

Cout is not a member of std, and other issues regarding c++

Allow me to preface this by saying that I do have included (also applies to string, endl, and quite literally everything doesn't work); my IDE is showing no errors as far as syntax goes; and I cannot understand why this issue is happening? It works fine in one of my other C++ code samples I wrote. So I am trying to make a small game, bulls and cows. My main code looks as follows: #incl

Cout不是std的成员,以及有关c ++的其他问题

请允许我在前面说,我已经包括了(也适用于字符串,endl,并且毫不夸张地说,一切都不起作用); 就语法而言,我的IDE没有显示任何错误; 我不明白为什么会发生这个问题? 它在我编写的其他C ++代码示例中工作正常。 所以我正在尝试做一个小游戏,公牛和牛。 我的主要代码如下所示: #include <iostream> #include "stdafx.h" #include "BullsAndCows.h" using std::cout; using std::endl; using std::cin; using

error: no matching function for call to 'std::map

typedef struct { string strDatabaseName; set <string, greater<string> > setDBAccName; } UserDBAInfo_t; typedef struct { map<int, UserDBAInfo_t > mapUserDBAInfo; } UserDBInfo_t; typedef set<string, greater<string> > setNames_t; int main( int argc, char * argv[] ) { ... map<string, UserDBInfo_t > mapHRUserDBInfo; UserDBInfo_t structUser

错误:没有匹配函数调用'std :: map

typedef struct { string strDatabaseName; set <string, greater<string> > setDBAccName; } UserDBAInfo_t; typedef struct { map<int, UserDBAInfo_t > mapUserDBAInfo; } UserDBInfo_t; typedef set<string, greater<string> > setNames_t; int main( int argc, char * argv[] ) { ... map<string, UserDBInfo_t > mapHRUserDBInfo; UserDBInfo_t structUser

Why does outputting a class with a conversion operator not work for std::string?

This works, printing 1: #include <iostream> struct Int { int i; operator int() const noexcept {return i;} }; int main() { Int i; i.i = 1; std::cout << i; } However, this fails to compile on GCC 4.8.1: #include <iostream> #include <string> struct String { std::string s; operator std::string() const {return s;} }; int main() { String s;

为什么使用转换运算符输出类不适用于std :: string?

这工作,打印1: #include <iostream> struct Int { int i; operator int() const noexcept {return i;} }; int main() { Int i; i.i = 1; std::cout << i; } 然而,这不能在GCC 4.8.1上编译: #include <iostream> #include <string> struct String { std::string s; operator std::string() const {return s;} }; int main() { String s; s.s = "hi";

Error using custom operator< with std::less

I am trying to overload the < operator, but running into a problem. Here is my implementation: int Vector3D::operator < (const Vector3D &vector) { if(x<vector.x) return 1; else return 0; } I am calling it using this code: std::map<Vector3D, std::vector<const NeighborTuple *> > position; std::set<Vector3D> pos; for (NeighborSet::iterator it

使用自定义运算符<使用std :: less时出错

我试图超载<运营商,但遇到问题。 这是我的实现: int Vector3D::operator < (const Vector3D &vector) { if(x<vector.x) return 1; else return 0; } 我使用下面的代码调用它: std::map<Vector3D, std::vector<const NeighborTuple *> > position; std::set<Vector3D> pos; for (NeighborSet::iterator it = N.begin(); it != N.end(); it++) { NeighborTuple c

std::endl is of unknown type when overloading operator<<

I overloaded operator << template <Typename T> UIStream& operator<<(const T); UIStream my_stream; my_stream << 10 << " heads"; Works but: my_stream << endl; Gives compilation error: error C2678: binary '<<' : no operator found which takes a left-hand operand of type 'UIStream' (or there is no acceptable conversion) What is the

当运算符<<重载时,std :: endl是未知类型

我重载了operator << template <Typename T> UIStream& operator<<(const T); UIStream my_stream; my_stream << 10 << " heads"; 工作但是: my_stream << endl; 给汇编错误: 错误C2678:二进制'<<':找不到操作符找到类型为'UIStream'的左操作数(或者没有可接受的转换) 什么是使my_stream << endl工作的工作? std::endl是一个函数, std:

ostream operator << in Namespace hides other ostream::operator

This question already has an answer here: Calling a function overloaded in several namespaces from inside one namespace 3 answers As stated here, this is an example of name hiding. By defining operator<< in namespace MyNamespace all the definitions from the higher namespaces (like global) are hidden. Note that as stated here: [...]this feature doesn't interfere with Koenig look

命名空间中的ostream运算符<<隐藏了其他ostream ::运算符

这个问题在这里已经有了答案: 在一个命名空间内调用一个在几个命名空间中重载的函数3个答案 如此处所述,这是一个名称隐藏的例子。 通过在命名空间MyNamespace定义operator<< ,所有来自较高命名空间(如全局)的定义都被隐藏起来。 请注意,如此处所述: 此功能不会干扰Koenig lookup [...],因此仍然会找到来自std:: IO运算符。 (有关Koenig查找的详细信息) 解决方法是using指令引用其他名称空间中的重

std::atomic error: no ‘operator++(int)’ declared for postfix ‘++’ [

I am trying to update an atomic variable through different threads and getting this error. This is my code. class counter { public: std::atomic<int> done; bool fn_write (int size) const { static int count = 0; if (count == size) { done++; count = 0; return false; } else { count++; return true;

std :: atomic错误:没有为后缀'++'声明'operator ++(int)'[

我试图通过不同的线程更新一个atomic变量,并得到这个错误。 这是我的代码。 class counter { public: std::atomic<int> done; bool fn_write (int size) const { static int count = 0; if (count == size) { done++; count = 0; return false; } else { count++; return true; } } }; int main() {

operator<< overloading "error: passing 'const...."

ofstream& operator<<(ostream &outStream, const EventClass &eventObject) { outStream << eventObject.getEventName() << " event at " << eventObject.getEventTime() << endl; return(outStream); } I believe this snippet is sufficient to analyze the error. When I compile my code I get the following errors: error: passing 'const EventClass' as

运算符<<重载“错误:传递'const ....”

ofstream& operator<<(ostream &outStream, const EventClass &eventObject) { outStream << eventObject.getEventName() << " event at " << eventObject.getEventTime() << endl; return(outStream); } 我相信这段代码足以分析错误。 当我编译我的代码时,出现以下错误: 错误:作为'std :: string EventClass :: getEventName()'的'this'参数传递&

How to use strongly typed enums

I'm not able to compile the following program: #include <iostream> using namespace std; enum class my_enum { ANT, BAT, CAT, DOG, EGG, FAN, MAX_MEMBERS }; int main(int argc, char * argv[]) { my_enum i = my_enum::ANT; for(i = my_enum::ANT; i < my_enum::MAX_MEMBERS; i++) { cout << "Enum value = " << i << endl; }

如何使用强类型枚举

我无法编译以下程序: #include <iostream> using namespace std; enum class my_enum { ANT, BAT, CAT, DOG, EGG, FAN, MAX_MEMBERS }; int main(int argc, char * argv[]) { my_enum i = my_enum::ANT; for(i = my_enum::ANT; i < my_enum::MAX_MEMBERS; i++) { cout << "Enum value = " << i << endl; } return 0; } 我看到构建