473,805 Members | 1,981 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

vector of (int,string). can't convert i->first to int

int first=15,latest =15; QString typ=NULL;
std::map<int,st d::string>::ite rator i;
for(i = SeznamPracovniD oby.begin(); i != SeznamPracovniD oby.end(); i++)
{ if (typ==NULL) typ=i->second.c_str() ;
if (typ!=i->second.c_str() ) {
std::cout<<firs t<<"-"<<latest<<":"< <typ; first=i->first; }
else { latest=i->first; typ=i->second.c_str() ; }
std::cout << i->first << " " << i->second << std::endl;
}
Aug 15 '07 #1
4 2192
"Milan Krejci" <rd*@no-spam.mail.czwro te in message
news:f9******** ***@news.vol.cz ...
int first=15,latest =15; QString typ=NULL;
std::map<int,st d::string>::ite rator i;
for(i = SeznamPracovniD oby.begin(); i != SeznamPracovniD oby.end();
i++)
{ if (typ==NULL) typ=i->second.c_str() ;
if (typ!=i->second.c_str() ) { std::cout<<firs t<<"-"<<latest<<":"< <typ;
first=i->first; }
else { latest=i->first; typ=i->second.c_str() ; }
std::cout << i->first << " " << i->second << std::endl;
}
I don't know what you are trying to show. Formatting your code and
replacing QString with std::string and changing it so it compiles, it
compiles.

#include <iostream>
#include <map>
#include <string>

int main()
{
std::map<int,st d::stringSeznam PracovniDoby;

int first=15,latest =15;
std::string typ;
std::map<int,st d::string>::ite rator i;
for(i = SeznamPracovniD oby.begin(); i != SeznamPracovniD oby.end(); i++)
{
if ( typ == "" )
typ = i->second.c_str() ;
if (typ!=i->second.c_str() )
{
std::cout<<firs t<<"-"<<latest<<":"< <typ;
first=i->first;
}
else
{
latest=i->first;
typ=i->second.c_str() ;
}
std::cout << i->first << " " << i->second << std::endl;
}

}

I don't know what you're trying to do though, and I don't know what QString
actually is. Post some compilable code that demonstrates the problem.
Aug 15 '07 #2
hello thanks for the reply.
i have a vector of 15,"something" ... 19,"something". ..20,"something
else".. 32,"something" and i'm trying to find out from what int to what
int there is "something" in the pair. in other words i need to get
first==15, latest==19, typ=="something " and
first==20, latest==31, typ=="something else".
QString was a QT toolkit's implementation of a string class.

Jim Langston napsal(a):
"Milan Krejci" <rd*@no-spam.mail.czwro te in message
news:f9******** ***@news.vol.cz ...
>int first=15,latest =15; QString typ=NULL;
std::map<int,st d::string>::ite rator i;
for(i = SeznamPracovniD oby.begin(); i != SeznamPracovniD oby.end();
i++)
{ if (typ==NULL) typ=i->second.c_str() ;
if (typ!=i->second.c_str() ) { std::cout<<firs t<<"-"<<latest<<":"< <typ;
first=i->first; }
else { latest=i->first; typ=i->second.c_str() ; }
std::cout << i->first << " " << i->second << std::endl;
}

I don't know what you are trying to show. Formatting your code and
replacing QString with std::string and changing it so it compiles, it
compiles.

#include <iostream>
#include <map>
#include <string>

int main()
{
std::map<int,st d::stringSeznam PracovniDoby;

int first=15,latest =15;
std::string typ;
std::map<int,st d::string>::ite rator i;
for(i = SeznamPracovniD oby.begin(); i != SeznamPracovniD oby.end(); i++)
{
if ( typ == "" )
typ = i->second.c_str() ;
if (typ!=i->second.c_str() )
{
std::cout<<firs t<<"-"<<latest<<":"< <typ;
first=i->first;
}
else
{
latest=i->first;
typ=i->second.c_str() ;
}
std::cout << i->first << " " << i->second << std::endl;
}

}

I don't know what you're trying to do though, and I don't know what QString
actually is. Post some compilable code that demonstrates the problem.

Aug 15 '07 #3
First you don't have a vector of anything.
It's a map.

Some points:

Initialize i inside the for unless you have
good reason to do otherwise.

Hopefully QString can handle being initialized
and compared to NULL. std::string won't.

Hopefully QString can be assigned a const char* and
there is a ostring << QString operator defined.

The if(typ==NULL) typ = i->second.c_str ()
line looks problematic. It causes you not
to do the setting of "first" the first time
through the loop. It looks to me you want to
delete this case and set typ to second.c_str()
inside the body of the next if. This assumes
that second will never contain something that
compares to a NULL typ.
Aug 15 '07 #4
LR
Milan Krejci wrote:

Probably better not to top post here, someone might complain about it.
hello thanks for the reply.
i have a vector
Minor point, but you mean a map, not a vector, right?

of 15,"something" ... 19,"something". ..20,"something
else".. 32,"something"
What do the ellipses represent? Are there other values?
15,"something"
16,"something"
17,"something"
18,"something"
19,"something"
20,"something else"
21,"something else"
and so on up to
31,"something else"
32,"something"
and i'm trying to find out from what int to what
int there is "something" in the pair.
Do you really mean "something" or just any value? Could we see:

10,"X"
11,"X"
12,""
13,""
14,"Y"
15,"X"
16,"X"
in other words i need to get
first==15, latest==19, typ=="something " and
first==20, latest==31, typ=="something else".
Given the data you provided, would you also see
first==32, latest==32, typ=="something "
QString was a QT toolkit's implementation of a string class.
Why are you using it? I think it just confuses the issue. For one
thing you're using std::string in your map, for another, it's not part
of the C++ standard and at least some of the readers here are unfamiliar
with it.

>
Jim Langston napsal(a):
>"Milan Krejci" <rd*@no-spam.mail.czwro te in message
I snipped the OPs code. Jim's is easier to read and edit, which I've done.

Did I say that Jim's code was easier to read because of the nice indenting?
>I don't know what you are trying to show. Formatting your code and
replacing QString with std::string and changing it so it compiles, it
compiles.

#include <iostream>
#include <map>
#include <string>

You might want to consider a typedef for this
typedef std::map<int,st d::stringMyMap; // or a better name

I'd think about putting this whole thing in a function. At the very
least it'll make it easier to test.

void first_last(cons t MyMap &SeznamPracovni Doby) {

if(SeznamPracov niDoby.empty())
return;

//> int first=15,latest =15;

How do you know that the first key in the map is 15?
// being at the start is just like being at the
// begining of a new 'typ', so initialize
// typ, first and latest
std::string typ = SeznamPracovniD oby.begin()->second;
int first = SeznamPracovniD oby.begin()->first;
// we're at the start so we initialize latest with first
// we should always do that when we are at the first entry
// of a 'typ'
int latest = first;


for(MyMap::cons t_iterator i = SeznamPracovniD oby.begin(); i !=
SeznamPracovniD oby.end(); i++) {

These next two lines aren't needed and raise the question of what
happens if the "something" in the first entry in the map has a value of
"". Or what if any entry in the map has a value of ""?

//> if ( typ == "" )
//> typ = i->second.c_str() ;
> if (typ!=i->second.c_str() )
{
std::cout<<firs t<<"-"<<latest<<":"< <typ;
did you want a '<< std::endl' at the end of that line?
> first=i->first;
There are some problems here. If you trace carefully though the code
and maybe add some trace you'll probably see it.

> }
else
{
Some problems here too. Same suggestion.
> latest=i->first;
typ=i->second.c_str() ;
}
Maybe this next line
// std::cout << i->first << " " << i->second << std::endl;
Should be
std::cout<<firs t<<"-"<<latest<<":"< <typ << std::endl;
> }

}
void test1() {
MyMap m;
// set up some data here and call the function
first_last(m);
}

put test2() and as many others as you want here...

I snipped this and moved it from above
int main()
{
test1();
test2();
// etc..
}

>>
I don't know what you're trying to do though, and I don't know what
QString actually is. Post some compilable code that demonstrates the
problem.

Good idea.

LR
Aug 15 '07 #5

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

Similar topics

10
6171
by: Sergio del Amo | last post by:
Hi, I am trying to create a web site to work in Opera 7.2, Explorer 6.0 and Mozilla 1.4. I have the code: var imgs= document.getElementsByTagName("img"); alert(imgs.id); The id of imgs is a10. A window is open with Opera, Explorer and Mozilla with the text "a10". When i write:
14
2741
by: Alex Vinokur | last post by:
Here is some function that detects if a vector contains only different elements bool vector_contains_only_different_elements (const vector<int>& v) { for (int i = 0; i < v.size(); i++) { if (count (v.begin() + i + 1, v.end(), v) >= 1) return false; } return true; }
34
4184
by: Adam Hartshorne | last post by:
Hi All, I have the following problem, and I would be extremely grateful if somebody would be kind enough to suggest an efficient solution to it. I create an instance of a Class A, and "push_back" a copy of this into a vector V. This is repeated many times in an iterative process. Ok whenever I "push_back" a copy of Class A, I also want to assign a pointer contained in an exisiting instance of a Class B to this
13
1540
by: Ivar | last post by:
Hi guys - So basically I am trying to implement a function that converts an int to a string, but it is not working for some reason - any thoughts? My function, intToStr, is shown below. I'm just trying to implement this to gain practice with c-style strings. #include<iostream> #include"testString.h" int main(int argc, char* argv) { char* c2 = new char;
10
14115
by: ypjofficial | last post by:
Hello All, In my program I am using a pointer to a vector vector<XYZ> * vptr = new vector<XYZ>; and also the XYZ class has a char* as one of its member.I have created all the copy constructor, assignment operator and destructor (The Big Three ) for XYZ. My question is how to free the memory held by vptr?
3
5857
by: eriwik | last post by:
I use the following structure to store filenames for one or more "sets" grouped together by a number: map<int, map<string> > fileSets; As arguments to the constructor I send a vector<vector<string> > where each vector<string> contains the filenames of one set. The function getNumber() calculates a number from the filename. The constructor then looks like this:
4
3086
by: Kim | last post by:
Random image downloader for specified newsgroup. Hi I'm writing a small script that will download random images from a specified newsgroup. I've imported yenc into the script but I can't open the image or save it. This is my first script so be gentle! Heres the script ####random group downloader#### import nntplib import string, random import mimetools import StringIO
1
2090
by: Alan | last post by:
I am wondering if anyone has any better idea of how to approach this problem than I do. . . . I have a vector of items (data). I have to do a pairwise comparison of each item to each other item and apply logic to see if one should be deleted. In the past I have done this using for statements, like: for (int i = 0; i < input_vector.size(); i++) for (int j = i; i < input_vector.size(); j++)
1
73051
by: rdraider | last post by:
I can't seem to find a way to convert an INT type in the form of YYYYMMDD to an actual date form of mm/dd/yyyy Can anyone pointt me in the right direction? Thanks
2
9664
karthickkuchanur
by: karthickkuchanur | last post by:
if((document.forms.employeeId.value == 0) && (document.forms.applicantId.value == 0)) { alert("Please Select the "+document.forms.type.value+" Code or Name"); return false; } i want to make the first letter into upper case in the document.forms.type.value thank u karthick
0
10360
jinu1996
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...
1
10366
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
10105
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...
1
7646
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
6876
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();...
0
5542
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...
0
5677
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3845
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3007
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.