473,791 Members | 3,229 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

stream to file a matrix

bob
Hi,

given a vector of vectors of strings thus;

typedef std::vector<std ::string> product;
typedef std::vector<pro duct> product_matrix;
whats the fastest, most efficient means of streaming the
"product_matrix " to a file? I.E. without using two "for" or "while"
loops. Is there a means of using copy ? I'd like to use stl's copy
along with my 2 dimensional vector of strings. Is that possible? Or
should I just iterate over the contents myself ?

thanks much

G

Mar 6 '06
11 1935
Fei Liu wrote:
Dietmar Kuehl wrote:
Ben Pope wrote:
> I would create a stream operator for product and product_matrix:


Note, that this code is not supposed to compile! The problem is
that output operator used by 'std::ostream_i terator<int>' is sought
only in namespace 'std'. However, since the involved types are all


what do you mean 'sought only in name space std'?


Which part you didn't understand? I'm not qualified to give you a
lecture in English and thus I assume you understood the statement
per se (otherwise use a dictionary).

On a technical level, 'std::ostream_i terator<T>' is a template and
look-up of names in separated into two phases which is thus called
two-phase-look-up. For the dependent names, i.e. those depending on
the template arguments, only the second phase, i.e. argument dependent
look-up, applies. The rules for this are that only namespace are
considered in which one of the arguments is defined (the specification
of this are tricky but just collecting all namespace qualifiers of the
fully qualified names of the arguments will to the trick). The only
namespace involved in you class is 'std', i.e. this is the only
namespace in which names are sought.
built-in types, you are - strictly speaking - not allowed to define
the output operator there! Technically, it is likely to work if you


I don't see the connection between built-in type and reason why output
operator is not allowed to be fined in 'std', can you elaborate on this
please?


It is a restriction imposed to protect the library implementation
from being hosed up by people defining more or less arbitrary
functions in namespace 'std': as a user of the standard C++ library
you are only allowed to define certain functions in namespace 'std'
and when you are allowed to define a function the signature has to at
least contain one user defined type.
just plug the output operators into namespace 'std' but the
behavior of the program is not defined.


Not sure about the meaning of 'plug the output operators into name
std'...And why is the program behavior not defined? The code seem to
compile/run perfectly.


I suggested to disobey the rules and define a function in namespace
'std' which are, strictly speaking, not allowed to define in
namespace 'std'. This is likely to work but the standard does not
give you any guarantee that it indeed will work because this violates
a specific restriction. These restrictions are there to protect the
library implementations : it is pretty easy to put functions into
namespace 'std' which will almost certainly cause the library to fail
in funny way. Also, compilation might easily fail if the library
implementor choose to put similar or even the same function into his
implementation.
--
<mailto:di***** ******@yahoo.co m> <http://www.dietmar-kuehl.de/>
<http://www.eai-systems.com> - Efficient Artificial Intelligence
Mar 8 '06 #11

Dietmar Kuehl wrote:
Fei Liu wrote:
Dietmar Kuehl wrote:
Ben Pope wrote:
> I would create a stream operator for product and product_matrix:

Note, that this code is not supposed to compile! The problem is
that output operator used by 'std::ostream_i terator<int>' is sought
only in namespace 'std'. However, since the involved types are all


what do you mean 'sought only in name space std'?


Which part you didn't understand? I'm not qualified to give you a
lecture in English and thus I assume you understood the statement
per se (otherwise use a dictionary).

On a technical level, 'std::ostream_i terator<T>' is a template and
look-up of names in separated into two phases which is thus called
two-phase-look-up. For the dependent names, i.e. those depending on
the template arguments, only the second phase, i.e. argument dependent
look-up, applies. The rules for this are that only namespace are
considered in which one of the arguments is defined (the specification
of this are tricky but just collecting all namespace qualifiers of the
fully qualified names of the arguments will to the trick). The only
namespace involved in you class is 'std', i.e. this is the only
namespace in which names are sought.
built-in types, you are - strictly speaking - not allowed to define
the output operator there! Technically, it is likely to work if you


I don't see the connection between built-in type and reason why output
operator is not allowed to be fined in 'std', can you elaborate on this
please?


It is a restriction imposed to protect the library implementation
from being hosed up by people defining more or less arbitrary
functions in namespace 'std': as a user of the standard C++ library
you are only allowed to define certain functions in namespace 'std'
and when you are allowed to define a function the signature has to at
least contain one user defined type.
just plug the output operators into namespace 'std' but the
behavior of the program is not defined.


Not sure about the meaning of 'plug the output operators into name
std'...And why is the program behavior not defined? The code seem to
compile/run perfectly.


I suggested to disobey the rules and define a function in namespace
'std' which are, strictly speaking, not allowed to define in
namespace 'std'. This is likely to work but the standard does not
give you any guarantee that it indeed will work because this violates
a specific restriction. These restrictions are there to protect the
library implementations : it is pretty easy to put functions into
namespace 'std' which will almost certainly cause the library to fail
in funny way. Also, compilation might easily fail if the library
implementor choose to put similar or even the same function into his
implementation.


Thank you, I didn't know there exists such kind of limitation on
implementing function in namespace 'std'. Too many rules...

Mar 9 '06 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1577
by: Sarah | last post by:
I would like my vb.net software running on an independent system be able to read the data going from a proprietary system to a dot-matrix printer. Few questions - are there any commercially available or "hack" devices available that would allow me to tap into the data the proprietary system is sending to the dot matrix printer? How could I get my vb.net software to respond listen to and respond to this data stream? Are there any...
2
9356
by: jjiyunlee | last post by:
Hi, I'm new to C (and programming in general), and I have to say that this site has helped me learn a great deal about C (thanks everybody!!). I've looked through several discussions specifically about reading a matrix from a file, but I think (based on my admittedly small amount of knowledge about things like this) that my problem is slightly different. My for-loops for fscanf-ing values from a user-specified file seems to be ignored...
1
2599
by: Michael | last post by:
I have a solution for this, but it feels wrong. If anyone could offer a better one, I'm all ears. (Or technically, eyes.) Basically, I have a bunch of classes. For concreteness, one is a Matrix class, but that's only one example, so please don't get too hung up on it. I need to output and input these classes. I'd like a nice, pretty, human readable output, something like: 1 2 3
10
7514
by: bodowpin | last post by:
Hello. I am trying to read a text file that contains 1 2 3 it just looks like that. I was able to read it and assign each number to a matrix element (or array element). It was reading it all fine and I was trying to change the elements to int variables a,b,c so that I could say matrix = {a,b,c}; At some point during tweaking all the matrix elements became 0 and I have lost myself.
103
5899
by: aboxylica | last post by:
hey! I have a program that takes two input files(one in the matrix form) and one in the sequence form.Now my problem is that i have to give the matrix file(containing many matrices) and sequence file containing many sequences and calculate the same log score as I did for one matrix file and one sequence file. how it should exactly work is that. for every sequence it should calculate log values for all the weight matrices,then go to the...
3
2217
by: craziileeboi | last post by:
Hi I have been pulling my hair out trying to figure this out. Please help!!! Here is my project description: By using a pointer to pointers **A and **B and the function calloc() allocate the memory for the 4x4 matrices A and B. By using the pointers *a and *b and the function malloc() allocate the memory for the 4-dimensional vectors a and b.
1
2673
by: dwaterpolo | last post by:
Hi Everyone, I am trying to read two text files swY40p10t3ctw45.col.txt and solution.txt and compare them, the first text file has a bunch of values listed like: y y y y y y y
23
1681
by: bc90021 | last post by:
Hi All, Thanks in advance for any and all help! I have this code: g = open(fileName, 'a') where fileName is defined before the line it's used in. It works fine when I use it outside a thread class.
5
2094
by: slizorn | last post by:
hi, well this is the file i have to read into the system... <matrix> rows = 2 cols = 2 1 2 2 4 </matrix>
0
9512
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10419
Oralloy
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...
1
10147
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,...
0
9987
tracyyun
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...
0
9023
agi2029
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...
1
7531
isladogs
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...
0
5424
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...
2
3709
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2910
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.