Thread: Vectors with GCC vs MSVC

  1. #1
    Registered User
    Join Date
    Nov 2013
    Posts
    107

    Vectors with GCC vs MSVC

    in gcc i can say

    Code:
    vector<string>arr;
    
    string str = "c:\\" + arr[0];
    yet in VC 2010 EE I can't do this, firstly I have to say

    Code:
    vector<string>arr;
    arr[0].c_str();
    then if I try,

    Code:
    string str = "C:\\" + arr[0].c_str();
    I get cannot add two pointers??

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You should be able to do the former with both, assuming that your vector has at least one element. The latter is wrong precisely because the string literal is converted to a pointer to its first element, and you cannot add two pointers.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Vectors in vectors - pointers and iterators
    By fisherking in forum C++ Programming
    Replies: 8
    Last Post: 07-27-2010, 09:34 AM
  2. msvc++ help
    By isnan in forum Windows Programming
    Replies: 1
    Last Post: 03-15-2004, 09:23 AM
  3. Using GCC with MSVC?
    By punkrockguy318 in forum C++ Programming
    Replies: 1
    Last Post: 01-02-2004, 12:46 PM
  4. msvc++ and STL
    By jahnoosh in forum C++ Programming
    Replies: 4
    Last Post: 11-24-2002, 02:24 PM