By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,797 Members | 1,794 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,797 IT Pros & Developers. It's quick & easy.

using map<int,string> in Linux

P: 1
Hi

I am new to this site and also to c++. The problem I am facing is that I when I run the following code, I expect to get '"Today is sunny" at the end of the program. And I do get it in Visual Studio but not in Linux(g++ 4.1.0, Fedora). What I get in Linux is "Todayissunny". I actually need the whole string with spaces in Linux to be a part of some other functions. Can anybody tell me where do the spaces go?

#include<string>
#include <iostream>
#include <map>
using namespace std;

int main ()
{
string st="Today is sunny";
char *p;
map<int, string> mymap;
map<int, string> yourmap;
typedef pair<int, string> pr;
map<int, string>::iterator pos;

mymap.insert(pr(1, st));
yourmap = mymap;
//cout << yourmap.begin()->second<<endl;

p=strtok((char*)mymap.begin()->second.c_str(), " ");
while(p!=NULL)
p=strtok(NULL, " ");

mymap = yourmap;
cout << mymap.begin()->second<<endl;
return 0;
}

Will appreciate any help.

-Khurram.
Nov 4 '06 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.