using map<int,string> in Linux

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mirkmmd
    New Member
    • Nov 2006
    • 1

    #1

    using map<int,string> in Linux

    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 "Todayissun ny". 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>::iterat or 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.
Working...