Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › getline(cin,string) and loops
New Posts  All Forums:Forum Nav:

getline(cin,string) and loops - Page 2

post #11 of 14
Quote:
Originally Posted by PRloaded;13567237 
got it!
I guess the whole clearing the buffer was the issue.
I still don't fully understand alot of the subtle inner workings of C++ yet.

One question though, can structures be initialized by variables?

if you look at my code you can see I made a structure for the ticket info.
I plan to fill them up with named variables with data in them every tutorial that I see has it like
Code:
ticketInfo fillTicket = {
"New York"
11
15
6
......
}

does it have to be like this or can I do
Code:
ticketInfo fillTicket = {
PassengerName
DepartureName
DestinationChoice
........
}

You can give your struct a constructor if you'd like, and pass values in that way, or you can set them manually. Once you've gone the route of giving it a constructor you might as well make it a class instead of a struct in my opinion.
Code:
struct ticketInfo
{
    std::string PassengerName;
    std::string DepartureName;
    std::string DestinationChoice;
    int testValue;
    bool testBool;

    // Default constructor
    ticketInfo() :
        testValue(0)
       , testBool(false)
       // We don't need to initialize the strings, they do that on their own
    {
    }

    // Constructor
    ticketInfo(std::string passenger, std::string departure, std::string destination, int testVal, bool testBoolean ) :
         , PassengerName(passenger)
         , DepartureName(departure)
         , DestinationChoice(destination)
         , testValue(testVal)
         , testBool(testBoolean)
    {
    }
}

// You can manually set each variable in a struct, because they're all public variables
ticketInfo fillTicket;
fillTicket.PassengerName = PassengerName;
fillTicket.DepartureName = DepartureName;
fillTicket.DestinationChoice = DestinationChoice;
fillTicket.testValue = 5;
fillTicket.testBool = true;

// Or you can use a constructor that you've made (safer, because you make sure everything gets initialized)
ticketInfo fillTicket(PassengerName, DepartureName, DestinationChoice, 5, true);
Foldatron
(17 items)
 
Mat
(10 items)
 
Work iMac
(9 items)
 
CPUMotherboardGraphicsGraphics
i7 950 EVGA x58 3-way SLI EVGA GTX 660ti GTX 275 
RAMHard DriveHard DriveHard Drive
3x2GB Corsair Dominator DDR3-1600 80GB Intel X25-M SSD 2TB WD Black 150GB WD Raptor 
Hard DriveOSMonitorKeyboard
2x 150GB WD V-raptor in RAID0 Win7 Home 64-bit OEM 55" LED 120hz 1080p Vizio MS Natural Ergonomic Keyboard 4000 
PowerCase
750W PC P&C Silencer CoolerMaster 690 
CPUGraphicsRAMHard Drive
Intel Core i5 2500S AMD 6770M 8GB (2x4GB) at 1333Mhz 1TB, 7200 rpm 
Optical DriveOSMonitorKeyboard
LG 8X Dual-Layer "SuperDrive" OS X Lion 27" iMac screen Mac wireless keyboard 
Mouse
Mac wireless mouse 
CPUGraphicsRAMHard Drive
i7-2600K AMD 6970M 1GB 16GB PC3-10600 DDR3 1TB 7200rpm 
Hard DriveOptical DriveOSMonitor
256GB SSD 8x DL "SuperDrive" OS X 10.7 Lion 27" 2560x1440 iMac display 
Monitor
27" Apple thunderbolt display 
  hide details  
Reply
Foldatron
(17 items)
 
Mat
(10 items)
 
Work iMac
(9 items)
 
CPUMotherboardGraphicsGraphics
i7 950 EVGA x58 3-way SLI EVGA GTX 660ti GTX 275 
RAMHard DriveHard DriveHard Drive
3x2GB Corsair Dominator DDR3-1600 80GB Intel X25-M SSD 2TB WD Black 150GB WD Raptor 
Hard DriveOSMonitorKeyboard
2x 150GB WD V-raptor in RAID0 Win7 Home 64-bit OEM 55" LED 120hz 1080p Vizio MS Natural Ergonomic Keyboard 4000 
PowerCase
750W PC P&C Silencer CoolerMaster 690 
CPUGraphicsRAMHard Drive
Intel Core i5 2500S AMD 6770M 8GB (2x4GB) at 1333Mhz 1TB, 7200 rpm 
Optical DriveOSMonitorKeyboard
LG 8X Dual-Layer "SuperDrive" OS X Lion 27" iMac screen Mac wireless keyboard 
Mouse
Mac wireless mouse 
CPUGraphicsRAMHard Drive
i7-2600K AMD 6970M 1GB 16GB PC3-10600 DDR3 1TB 7200rpm 
Hard DriveOptical DriveOSMonitor
256GB SSD 8x DL "SuperDrive" OS X 10.7 Lion 27" 2560x1440 iMac display 
Monitor
27" Apple thunderbolt display 
  hide details  
Reply
post #12 of 14
Thread Starter 
thanks alot guys.
I pick up something new every day.
post #13 of 14
Quote:
Originally Posted by PRloaded View Post
I attended SDSU but I didn't like their engineering department so I'm currently at Southwestern so I can transfer next year to UCSC. This programming class is actually from San Diego City College and it's online so I can't really give my opinion on their program
I'm taking a physics course this summer at UCSC...that campus location is perfection...I just finished a c++ online course...got into inheritance, polymorphism, operator overloading...good stuff.
Edited by surfbumb - 5/19/11 at 10:58pm
Black Silence
(15 items)
 
  
CPUMotherboardRAMHard Drive
i5 3570k @ 4.5 GHz Asus P8Z77-M Pro Kingston HyperX Genesis 8 GB - 1600 MHz Seagate Barracuda 250 GB 
Optical DriveCoolingOSMonitor
Samsung WriteMaster Noctua NH-D14 Windows 10 ASUS VS24AH-P 
KeyboardPowerCaseMouse
Logitech Navigator Enermax Infiniti 650W Fractal R3 Black Pearl Razer Death Adder 
Mouse PadAudio
SteelSeries QcK Mass Altec Lansing FX4021 
  hide details  
Reply
Black Silence
(15 items)
 
  
CPUMotherboardRAMHard Drive
i5 3570k @ 4.5 GHz Asus P8Z77-M Pro Kingston HyperX Genesis 8 GB - 1600 MHz Seagate Barracuda 250 GB 
Optical DriveCoolingOSMonitor
Samsung WriteMaster Noctua NH-D14 Windows 10 ASUS VS24AH-P 
KeyboardPowerCaseMouse
Logitech Navigator Enermax Infiniti 650W Fractal R3 Black Pearl Razer Death Adder 
Mouse PadAudio
SteelSeries QcK Mass Altec Lansing FX4021 
  hide details  
Reply
post #14 of 14
Thread Starter 
Quote:
Originally Posted by surfbumb View Post
I'm taking a physics course this summer at UCSC...that campus location is perfection...I just finished a c++ online course...got into inheritance, polymorphism, operator overloading...good stuff.
UCSC is beautiful....


It's just a shame that I'm really bad with keeping up with work and my GPA is in the tank

i took 21 units this semester to hail mary into UCSC. Didn't work...
Had to suffer the rest of the semester with a workload I could barely handle.
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › getline(cin,string) and loops