Inserting struct data into a vector?

This is a discussion on Inserting struct data into a vector? within the C++ Programming forums, part of the General Programming Boards category; Hmm.. So why don't you use std:: in arrays for example? Got any good link if you want to learn ...

  1. #16
    Registered User
    Join Date
    May 2008
    Posts
    62
    Hmm.. So why don't you use std:: in arrays for example?
    Got any good link if you want to learn "a->b is equivalent to (*a).b." a little better?

  2. #17
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,700
    >> Hmm.. So why don't you use std:: in arrays for example?

    They aren't in a namespace by default for the same reason a vanilla class isn't in a namespace by default. Arrays are a language construct, not a part of the standard libraries.

    >> Any good link

    Well it's probably in a C++ book near the pointers chapter.

    The jist is as you heard, a is a pointer to a struct, class or union, and b is a member.

    a->b dereferences a before accessing b.
    (*a).b is the same thing, but the syntax is a bit convoluted, yet necessary, because dereferencing has a lower precedence then the dot operator; that is, you cannot access members of a pointer's type without dereferencing a pointer first.

    Get a book and look up a C++ operator precedence chart.

  3. #18
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,604
    Quote Originally Posted by Glauber View Post
    Hmm.. So why don't you use std:: in arrays for example?
    Because arrays is not in the std namespace.

    Got any good link if you want to learn "a->b is equivalent to (*a).b." a little better?
    I suggest you get a good book. Those belong to pointers and merely understanding the syntax is not enough. You need to know how pointers work in general.

    A book would help on the namespace issue, as well.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #19
    Registered User
    Join Date
    May 2008
    Posts
    62
    Thank you all.

    Code:
    struct data {
      string name;
      string title;
      string author;
    };
    
    vector <data> books;
    I would be glad to know, for educational purposes, how you combine your suggestions about maps (ID), with that struct and vector?

  5. #20
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,700
    Ask yourself how data will be used and then choose or implement the design that fascilitates this use.

  6. #21
    Registered User
    Join Date
    May 2008
    Location
    Paris
    Posts
    248
    Got any good link if you want to learn "a->b is equivalent to (*a).b." a little better?
    *this

  7. #22
    Registered User
    Join Date
    May 2008
    Posts
    62
    How would you store the data inside a .txt file, so you can request data from the .txt file that is already there, or store additional data?

  8. #23
    Registered User
    Join Date
    May 2008
    Posts
    62

    Storing and accessing data from and to .txt files.

    How would you store string data inside a .txt file, so you can request data from the .txt file that is already there, or store additional data?

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bitmasking Problem
    By mike_g in forum C++ Programming
    Replies: 13
    Last Post: 11-07-2007, 11:24 PM
  2. Global Variables
    By Taka in forum C Programming
    Replies: 34
    Last Post: 11-02-2007, 03:25 AM
  3. Bi-Directional Linked Lists
    By Thantos in forum C Programming
    Replies: 6
    Last Post: 12-11-2003, 09:24 AM
  4. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM

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