C++ Struct Question

Discussion in 'Web Design & Coding' started by dubstar, Sep 4, 2008.

  1. dubstar

    dubstar format c:

    Messages:
    1,357
    Location:
    Southern California
    my first Struct:

    Code:
    struct menuType		//struct definition
    {
    	string itemName;	//name of item
    	double itemPrice;	//price of item
    };
    
    string getMenu()
    {
    	ifstream menuList;
    	menuList.open("menuList.txt");
    	if (menuList.is_open())
    	{
    		while (! menuList.eof())
    		{
    			cin.getline (menuInfo.itemName,menuInfo.itemPrice);
    		}
    	}
    };

    what am i doing wrong ?? :(
     
  2. X-Istence

    X-Istence * Political User

    Messages:
    6,498
    Location:
    USA
  3. dubstar

    dubstar format c:

    Messages:
    1,357
    Location:
    Southern California
    i was trying to open a file, read it, and then have each line stored into alternating variables.

    the first line would be itemName, then itemPrice. until the end of the file.

    thanks for the link.
     
  4. Geffy

    Geffy Moderator Folding Team

    Messages:
    7,805
    Location:
    United Kingdom
    where does menuInfo come from? You might need an input string stream (istringstream) but I'm not sure.