Should the following work? It does on some compilers. How can I get it to
work on g++ 3.2?
On g++ 3.2 it keeps telling me that there is no such function operator <<
for ostream and pair<string,str ing>. But there is!
And I can call it! And it works! So why cannot std::copy find it?
thanks,
Siegfried
template<typena me K, typename V>
ostream& operator<<(ostr eam& os, std::pair<K,V>& p){ return os << p.first <<
p.second; }
std::map<string ,string> m; m[(string)"hello"] = (string)"there" ;
std::copy(m.beg in(), m.end(), ostream_iterato r<std::pair<str ing,string> (cout, ","); 1 2894
Siegfried Heintze wrote: Should the following work? It does on some compilers. How can I get it to work on g++ 3.2?
Compiler-specific questions should be asked in the newsgroup dedicated
to that compiler. Try gnu.g++.help.
On g++ 3.2 it keeps telling me that there is no such function operator << for ostream and pair<string,str ing>. But there is!
Where?
And I can call it! And it works! So why cannot std::copy find it?
thanks, Siegfried
template<typena me K, typename V> ostream& operator<<(ostr eam& os, std::pair<K,V>& p){ return os << p.first << p.second; }
Is that what you wrote? Where does this definition appear? In
the global scope?
std::map<string ,string> m; m[(string)"hello"] = (string)"there" ; std::copy(m.beg in(), m.end(), ostream_iterato r<std::pair<str ing,string> (cout, ",");
Argument-dependent lookup (ADL) does not look in all the namespaces.
It limits its search to the types involved and the namespaces where
those types are defined. You need to place your operator in 'std'
namespace.
Next time please follow the recommendations of FAQ 5.8.
V
--
Please remove capital As from my address when replying by mail This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: sks_cpp |
last post by:
map<int, Drive*> dMap;
list<Drive*> dList;
copy( dMap.begin(), dMap.end(), back_inserter(dList) ); // incorrect
The above will not because value_type of dMap is different than dList.
Now, I would like to wrap the map iterators inside a class class (let's call
it WrapMap)
WrapMap wm(dMap.begin(), dMap.end() );
|
by: Jeff |
last post by:
std::copy to std::ostream_iterator doesn't seem to
work with maps and pairs.
Shouldn't I expect something like this to work?
The G++ error message when USE_COPY_TO_PRINT is
defined as a non-zero number follows.
---------------- error message --------------------
|
by: Serengeti |
last post by:
Hello,
in my class I have a map that translates strings to pointers to some
member functions. The code goes like this:
class F {
typedef void (Function::*MathFuncPtr)();
std::map<std::string, MathFuncPtr> predefinedFunctions;
// lots of other stuff
void makeDictionary(){ predefinedFunctions=&F::f_sin(); }
};
|
by: Saeed Amrollahi |
last post by:
Dear All C++ Programmers
Hello
I am Saeed Amrollahi. I am a software engineer in
Tehran Sewerage Company. I try to use std::map and map::find member
function. I
use Visual Studio .NET. my program uses two MFC classes: CRect and
CPoint
which represents Rectangle and Point concepts (as usual) and a user
|
by: Erik Wikström |
last post by:
First of all, forgive me if this is the wrong place to ask this question,
if it's a stupid question (it's my second week with C++), or if this is
answered some place else (I've searched but not found anything).
Here's the problem, I have two sets of files, the name of a file contains a
number which is unique for each set but it's possible (even probable) that
two files in different sets have the same numbers. I want to store these...
| |
by: Avery Fong |
last post by:
The following program will result in a compile error when building under Debug but will compile under Release. Why does is work under Release mode but not under Debug
This program is developed under Visual Studio .NET 2003 in a Win32 Console Project
// VectorInsert.cpp : Defines the entry point for the console application
/
#include "stdafx.h
#include "VectorInsert.h
#ifdef _DEBU
|
by: kamaraj80 |
last post by:
Hi
I am using the std:: map as following.
typedef struct _SeatRowCols
{
long nSeatRow;
unsigned char ucSeatLetter;
}SeatRowCols;
typedef struct _NetData
|
by: Chris Johnson |
last post by:
Greetings all. I am really stuck on this one as I can't seem to grok if
I am abusing the C++ language or if I am simply using components of the
C++ Standard Library incorrectly. Here is the code:
#include <string>
#include <map>
#include <iostream>
#include <utility>
#include <iterator>
|
by: mveygman |
last post by:
Hi,
I am writing code that is using std::map and having a bit of an issue
with its performance.
It appears that the std::map is significantly slower searching for an
element then a sequential search in a vector.
Has anyone run into this before?
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |