msvc++ and STL

This is a discussion on msvc++ and STL within the C++ Programming forums, part of the General Programming Boards category; Hi i just got msvc++ 6.0 Im wondering why this code won't compile: Code: //Address.h #ifndef Address_dot_h #define Address_dot_h 1 ...

  1. #1
    jahnoosh
    Guest

    msvc++ and STL

    Hi i just got msvc++ 6.0
    Im wondering why this code won't compile:
    Code:
    //Address.h
    
    #ifndef Address_dot_h
    #define Address_dot_h 1
    
    class Address
    {
    public:
    	
    	Address();
    
    	const char* lastname() const { return lastname_; }
    	void lastname(const char*);
    
    	const char* firstname() const { return firstname_; }
    	void firstname(const char*);
    
    	const char* phone() const { return phone_; }
    	void phone(const char*);
    
    	const char* address() const { return address_; }
    	void address(const char*);
    
    private:
    
    	enum { namelen = 16, phonelen = 16, addrlen = 100 };
    
    	char lastname_[namelen];
    	char firstname_[namelen];
    	char phone_[phonelen];
    	char address_[addrlen];
    };
    
    #endif
    
    //Address.cpp
    #include "Address.h"
    #include <string.h>
    
    
    Address::Address()
    {
    	lastname_[0] = firstname_[0] = phone_[0] = address_[0] = '\0';
    }
    
    void Address::lastname(const char* s)
    {
    	std::strcpy(lastname_, s);
    }
    
    void Address::firstname(const char* s)
    {
    	std::strcpy(firstname_, s);
    }
    
    void Address::phone(const char* s)
    {
    	std::strcpy(phone_, s);
    }
    
    void Address::address(const char* s)
    {
    	std::strcpy(address_, s);
    }
    
    //tester.cpp
    #include "iostream.h"
    #include "Address.h"
    
    void dump(const Address& a)
    {
         std::cout << a.firstname() << ' ' << a.lastname() << '\n'
                   << a.address() << '\n' << a.phone  << '\n'
                   << std::endl;
    }
    int main()
    {
        Address a;
        a.lastname("Smith");
        a.firstname("Joan");
        a.phone("(905) 684-2222");
        a.address("222 shooter lane, williamington manitoba");
        dump(a);
    
    
        a.phone("((906) 456 6543 ext 666");
        dump(a);
        return 0;
    }
    does msvc++ have a problen with STL action or what
    i get these and there are 5 of them:

    error C2653: 'std' : is not a class or namespace name

    thanks for any help on this

  2. #2
    Registered User
    Join Date
    Sep 2002
    Posts
    272
    You're not including the std headers. Try

    #include <iostream>
    #include <cstring>

    etc
    Joe

  3. #3
    jahnoosh
    Guest
    ok ive made the changes but it still doesn't compile and has the same errors
    [code]
    //Address.h

    #ifndef Address_dot_h
    #define Address_dot_h 1

    class Address
    {
    public:

    Address();

    const char* lastname() const { return lastname_; }
    void lastname(const char*);

    const char* firstname() const { return firstname_; }
    void firstname(const char*);

    const char* phone() const { return phone_; }
    void phone(const char*);

    const char* address() const { return address_; }
    void address(const char*);

    private:

    enum { namelen = 16, phonelen = 16, addrlen = 100 };

    char lastname_[namelen];
    char firstname_[namelen];
    char phone_[phonelen];
    char address_[addrlen];
    };

    #endif

    //Address.cpp
    #include "Address.h"
    #include <cstring>


    Address::Address()
    {
    lastname_[0] = firstname_[0] = phone_[0] = address_[0] = '\0';
    }

    void Address::lastname(const char* s)
    {
    std::strcpy(lastname_, s);
    }

    void Address::firstname(const char* s)
    {
    std::strcpy(firstname_, s);
    }

    void Address:hone(const char* s)
    {
    std::strcpy(phone_, s);
    }

    void Address::address(const char* s)
    {
    std::strcpy(address_, s);
    }

    //tester.cpp
    #include "iostream.h"
    #include "Address.h"
    #include <cstring>
    void dump(const Address& a)
    {
    std::cout << a.firstname() << ' ' << a.lastname() << '\n'
    << a.address() << '\n' << a.phone << '\n'
    << std::endl;
    }
    int main()
    {
    Address a;
    a.lastname("Smith");
    a.firstname("Joan");
    a.phone("(905) 684-2222");
    a.address("222 shooter lane, williamington manitoba");
    dump(a);


    a.phone("((906) 456 6543 ext 666");
    dump(a);
    return 0;
    }

  4. #4
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    Your dump() function needs work for starters. See if you can see whats wrong with it yourself. If you cant ill tell you later.

    As for the errors just make sure you are including the right headers.....

    MSVC can be a pain sometimes. for starters take out all explicit std:: 's then add a using namespace std;. Get it running first. Then go through and change it to explicit std:: if u must or just using std::cout; blah blah. Some things in msvc hat should be inside namespace std are not. Check out <cstdlib> for instance. Nothing there is in namespace std although it all should be.Well that was state of play at msvc6. Not sure about .net but i hear its much better than 6.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  5. #5
    jahnoosh
    Guest
    thats the only way i kno how to do it
    im not sure where to put the using namespace std;
    and dump is not a function i need its just to test the access
    im not very fluent in c++ especcially in this new msvc++ enviroment 6.0 by the way
    like to try .net but its much too many gold peices for me

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MSVC 05 STL still not portable across DLLs?
    By VirtualAce in forum Game Programming
    Replies: 0
    Last Post: 05-07-2006, 02:30 PM
  2. DLL question
    By cboard_member in forum Game Programming
    Replies: 1
    Last Post: 04-24-2006, 02:19 AM
  3. STL thread safety
    By Hunter2 in forum C++ Programming
    Replies: 4
    Last Post: 10-06-2004, 08:09 PM
  4. STL + MSVC++ = big executables ?
    By teneniel in forum C++ Programming
    Replies: 6
    Last Post: 11-04-2002, 01:12 PM
  5. Using STL List
    By Eber Kain in forum C++ Programming
    Replies: 2
    Last Post: 09-26-2002, 12:11 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21