CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Threaded View

  1. #1
    Join Date
    Feb 2008
    Posts
    3

    Thumbs down std::vector mangles a char* [SOLVED]

    Code:
    char* cFileIO::readStringFromFile()
    {
       string line;
       getline(*readFile, line);
       char str[70];
       strcpy(str, line.c_str());
       printf("%s\n", str);
       char* tosaveto = str;
       return tosaveto;
    }

    Code:
    for(int x=0; x<map->numCountries; x++)
       {
          char* t = readStringFromFile();
          printf("%s\n", t);
          map->countryNames.push_back(t);
          printf("%s\n", map->countryNames[x]);
          map->countryRects.push_back(readRectFromFile());
       }
    When I call push_back(t), the string gets mangled. The first time I printf it it's fine, but the second time it's mangled. Anyone have any ideas?

    The rectangle vertices come out printed fine, it's just the char*s that don't.
    Last edited by kerzack; February 7th, 2008 at 11:09 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured