The following code will compile. I have one line commented out because it
won't compile. Why can I not do this:
//set<string>::iterator iterator = s->begin();
Why do I have to deference the set when I receive it as a pointer? Is that
just the way we are supposed to do it, or am I missing something?
-------------------------------------------------
#include <iostream>
#include <set>
#include <string>
using namespace std;
typedef set<stringStringSet;
void zoot(set<string* s);
int main()
{
set<strings;
s.insert("aaa");
s.insert("bbb");
zoot( &s );
return 0;
}
void zoot(set<string* s )
{
// This won't compile - why?
//set<string>::iterator iterator = s->begin();
// dereference s, use s1, and it compiles
set<strings1 = *s;
for( set<string>::iterator iterator1 = s1.begin();iterator1 !=
s1.end();iterator1++)
{
cout << *iterator1;
}
} 9 2672
Zootal wrote:
The following code will compile. I have one line commented out because it
won't compile. Why can I not do this:
//set<string>::iterator iterator = s->begin();
Why do I have to deference the set when I receive it as a pointer? Is that
just the way we are supposed to do it, or am I missing something?
-------------------------------------------------
#include <iostream>
#include <set>
#include <string>
using namespace std;
typedef set<stringStringSet;
void zoot(set<string* s);
int main()
{
set<strings;
s.insert("aaa");
s.insert("bbb");
zoot( &s );
return 0;
}
void zoot(set<string* s )
{
// This won't compile - why?
//set<string>::iterator iterator = s->begin();
// dereference s, use s1, and it compiles
set<strings1 = *s;
for( set<string>::iterator iterator1 = s1.begin();iterator1 !=
s1.end();iterator1++)
{
cout << *iterator1;
}
}
What compiler and what error message ?
You could try (*s).begin() , MSVC6 had problems with s-syntax
sometimes, it did not correctly implement templates for obvious reasons.
ismo
I use MSVC6 to compile your code. It's OK. There is not any complile
errors. (before compile I and a '}' and then restore the line that you
comment out )
On 3ÔÂ13ÈÕ, ÏÂÎç12ʱ05·Ö, "Zootal" <nousenets...@zootal.nospam.comwrote:
The following code will compile. I have one line commented out because it
won't compile. Why can I not do this:
//set<string>::iterator iterator = s->begin();
Why do I have to deference the set when I receive it as a pointer? Is that
just the way we are supposed to do it, or am I missing something?
-------------------------------------------------
#include <iostream>
#include <set>
#include <string>
using namespace std;
typedef set<stringStringSet;
void zoot(set<string* s);
int main()
{
set<strings;
s.insert("aaa");
s.insert("bbb");
zoot( &s );
return 0;
}
void zoot(set<string* s )
{
// This won't compile - why?
//set<string>::iterator iterator = s->begin();
// dereference s, use s1, and it compiles
set<strings1 = *s;
for( set<string>::iterator iterator1 = s1.begin();iterator1 !=
s1.end();iterator1++)
{
cout << *iterator1;
}
}- Òþ²Ø±»ÒýÓÃÎÄ×Ö -
- ÏÔʾÒýÓõÄÎÄ×Ö -
Have you tried passing the set by reference?
void zoot(set<string& s )
{
set<string>::iterator it;
for (it = s.begin(); it != s.end(); ++it)
{
cout << *it;
}
}
On 13 mar, 01:05, "Zootal" <nousenets...@zootal.nospam.comwrote:
The following code will compile. I have one line commented out because it
won't compile. Why can I not do this:
//set<string>::iterator iterator = s->begin();
Why do I have to deference the set when I receive it as a pointer? Is that
just the way we are supposed to do it, or am I missing something?
-------------------------------------------------
#include <iostream>
#include <set>
#include <string>
using namespace std;
typedef set<stringStringSet;
void zoot(set<string* s);
int main()
{
set<strings;
s.insert("aaa");
s.insert("bbb");
zoot( &s );
return 0;
}
void zoot(set<string* s )
{
// This won't compile - why?
//set<string>::iterator iterator = s->begin();
// dereference s, use s1, and it compiles
set<strings1 = *s;
for( set<string>::iterator iterator1 = s1.begin();iterator1 !=
s1.end();iterator1++)
{
cout << *iterator1;
}
}
It compiles here, VS 2005.
gethostbyname
>
It compiles here, VS 2005.
I'm using VS2003. I tried it on my desktop, and it compiles fine. My
laptop has VS2003 academic version, and it gives an error - I don't
have it with me now so I can't post the actual error, but I can do
that tonight. WTF? Is anyone aware of any differences between the
academic version and the retail version?
You could try (*s).begin() , MSVC6 had problems with s-syntax
sometimes, it did not correctly implement templates for obvious reasons.
ismo
Interesting enough, that fixed another problem I had. I was doing
this:
Item* bb = *iterator;
And using bb because I couldn't figure out how to use the item the
iterator was pointing to, until I figured out I can use (*iterator)
instead. Thanks for the info :)
Ook wrote:
>It compiles here, VS 2005.
I'm using VS2003. I tried it on my desktop, and it compiles fine. My
laptop has VS2003 academic version, and it gives an error - I don't
have it with me now so I can't post the actual error, but I can do
that tonight. WTF? Is anyone aware of any differences between the
academic version and the retail version?
People in 'microsoft.public.vc.language' probably are.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
"Zootal" <no**********@zootal.nospam.comwrote in message
news:AZ******************************@giganews.com ...
The following code will compile. I have one line commented out because it
won't compile. Why can I not do this:
//set<string>::iterator iterator = s->begin();
<snip>
So I get home tonight, load the project, and it compiles. I spent an hour
banging my head against the wall, wondering why it would not compile. I'm
loosing it. Microsoft products hate me because I run linux on my server,
that must be it...
On 13 mar, 22:11, "Zootal" <nousenets...@zootal.nospam.comwrote:
"Zootal" <nousenets...@zootal.nospam.comwrote in message
news:AZ******************************@giganews.com ...The following code will compile. I have one line commented out because it
won't compile. Why can I not do this:
//set<string>::iterator iterator = s->begin();
<snip>
So I get home tonight, load the project, and it compiles. I spent an hour
banging my head against the wall, wondering why it would not compile. I'm
loosing it. Microsoft products hate me because I run linux on my server,
that must be it...
IMHO, if you would like to work with VS, use the 2005 Edition. Or use
gcc on Win :-)
gethostbyname This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: aquanutz |
last post by:
Ok, I have a list of strings (list<string> stringList) that I want to
sort alphabetcially, only "sort(stringList.begin(), stringList.end());
) does not work. Any insight would be helpful. Thanks!
|
by: Steve Edwards |
last post by:
Hi,
1)
I'm making a container for string pointers...
set<string*> strSet;
strSet.insert(...); // insert some strings
....
|
by: KL |
last post by:
I have a problem trying to write to a binary file that I want to name
after a particular name from a set. My code for the function follows,
please excuse the horrible mistakes you may see, I am a...
|
by: buzzweetman |
last post by:
Many times I have a Dictionary<string, SomeTypeand need to get the
list of keys out of it as a List<string>, to pass to a another method
that expects a List<string>.
I often do the following:
...
|
by: Martin Jørgensen |
last post by:
Hi,
The piece of code I'm struggling with is so simple, that I hope nobody
wants a complete example for answering the question:
--------
string color_line;
int data_type = 0;
for(...
|
by: Mark S. |
last post by:
Hello,
The app in question is lives on a Windows 2003 server with .NET 2.0 running
IIS 6. The page of the app in question processes 2000 get requests a second
during peak loads.
The app uses...
|
by: parez |
last post by:
Hi,
I am trying to serialize List<List<string>.
With the following code
public List<List<string>DataRows { get; set; }
|
by: barcaroller |
last post by:
In the boost::program_options tutorial, the author included the following
code:
cout << "Input files are: "
<< vm.as< vector<string()
<< "\n";
Basically, he is trying to print a vector...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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,...
|
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...
|
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...
| |