Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › MS Visual C++ 2010 Express. C++0x features
New Posts  All Forums:Forum Nav:

MS Visual C++ 2010 Express. C++0x features - Page 2

post #11 of 18
Thread Starter 
Quote:
Originally Posted by selectstriker2 View Post
curious why you are trying
for (int& n : arr) instead of

for (i; i < 10; i++)
thats what the book told me to do, c++0x feature "ranged-based for statement"...I do not understand its meant to make it easier to write when making for statements that go through arrays. or something, confusing me is what it is doing

Book

Quote:
for(base_type& variable : container) // Reference
statement

for(base_type variable : container) // By value
statement
Next one
(15 items)
 
  
CPUMotherboardGraphicsRAM
I5 3570k Asus P8Z77-V LK N760 TF F3-10666CL9S-4GBRL 
Hard DriveHard DriveHard DriveOptical Drive
Crucial M4 Kingston SNV125-S2BD Seagate Barracuda ST31000524AS Generic HP RW 
CoolingCoolingOSMonitor
Hyper 212 Evo Fans Windows 7 Pro x64 Samsung SyncMaster 2233SW 
PowerCaseAudio
Seasonic SSR-650RM 650w Storm Trooper Triton ax 720 
  hide details  
Reply
Next one
(15 items)
 
  
CPUMotherboardGraphicsRAM
I5 3570k Asus P8Z77-V LK N760 TF F3-10666CL9S-4GBRL 
Hard DriveHard DriveHard DriveOptical Drive
Crucial M4 Kingston SNV125-S2BD Seagate Barracuda ST31000524AS Generic HP RW 
CoolingCoolingOSMonitor
Hyper 212 Evo Fans Windows 7 Pro x64 Samsung SyncMaster 2233SW 
PowerCaseAudio
Seasonic SSR-650RM 650w Storm Trooper Triton ax 720 
  hide details  
Reply
post #12 of 18
Code:
#include <StdAfx.h>
#include <iostream>
#include <cstdlib>
using namespace std;

#define SIZE_OF_ARRAY 5


int main()
{
int arr[SIZE_OF_ARRAY];
int total = 0;

for (int i = 0; i < SIZE_OF_ARRAY; i++) {
cout << "Enter array value: ";
cin >> n;
total += n;
}
cout << "Here are the values: ";

for (int n : arr)
cout << n << endl;

cout << "Total is: " << total << endl << "Now, I'm going to zero out " << "the values. " << endl;

for (int& n : arr)
n = 0;

cout << "Here are the values: ";
for (int n : arr)
cout << n << endl;


cout << endl << endl;
cout << "Program Finished" << endl;
system("pause");
return 0;
}
Try that.
    
CPUMotherboardGraphicsGraphics
FX-8350 Asus Crosshair V MSI GTX460 Hawk 1gb MSI GTX460 Hawk 1gb 
RAMHard DriveHard DriveHard Drive
Kingston HyperX 8gb (2x4gb) Crucial M4 64GB Samsung F3 1TB Western Digital 320GB 
CoolingOSMonitorMonitor
Custom WC Windows 7 Ultimate X64 Dell E2311H Dell E2311H 
MonitorKeyboardPowerCase
LH 23EN43 Ducky Year of the Dragon 2012 SilverStone Strider 1000W-P Corsair 800D 
Audio
Asus Xonar Essence STX 
  hide details  
Reply
    
CPUMotherboardGraphicsGraphics
FX-8350 Asus Crosshair V MSI GTX460 Hawk 1gb MSI GTX460 Hawk 1gb 
RAMHard DriveHard DriveHard Drive
Kingston HyperX 8gb (2x4gb) Crucial M4 64GB Samsung F3 1TB Western Digital 320GB 
CoolingOSMonitorMonitor
Custom WC Windows 7 Ultimate X64 Dell E2311H Dell E2311H 
MonitorKeyboardPowerCase
LH 23EN43 Ducky Year of the Dragon 2012 SilverStone Strider 1000W-P Corsair 800D 
Audio
Asus Xonar Essence STX 
  hide details  
Reply
post #13 of 18
Thread Starter 
I am not going to try and quote everyone post, I know how the for statement works. this is the new for statement for c++0x, ranged-based for
Next one
(15 items)
 
  
CPUMotherboardGraphicsRAM
I5 3570k Asus P8Z77-V LK N760 TF F3-10666CL9S-4GBRL 
Hard DriveHard DriveHard DriveOptical Drive
Crucial M4 Kingston SNV125-S2BD Seagate Barracuda ST31000524AS Generic HP RW 
CoolingCoolingOSMonitor
Hyper 212 Evo Fans Windows 7 Pro x64 Samsung SyncMaster 2233SW 
PowerCaseAudio
Seasonic SSR-650RM 650w Storm Trooper Triton ax 720 
  hide details  
Reply
Next one
(15 items)
 
  
CPUMotherboardGraphicsRAM
I5 3570k Asus P8Z77-V LK N760 TF F3-10666CL9S-4GBRL 
Hard DriveHard DriveHard DriveOptical Drive
Crucial M4 Kingston SNV125-S2BD Seagate Barracuda ST31000524AS Generic HP RW 
CoolingCoolingOSMonitor
Hyper 212 Evo Fans Windows 7 Pro x64 Samsung SyncMaster 2233SW 
PowerCaseAudio
Seasonic SSR-650RM 650w Storm Trooper Triton ax 720 
  hide details  
Reply
post #14 of 18
Quote:
Originally Posted by Droo k6 View Post
I am not going to try and quote everyone post, I know how the for statement works. this is the new for statement for c++0x, ranged-based for
I havent used that sorry, cant help.
    
CPUMotherboardGraphicsGraphics
FX-8350 Asus Crosshair V MSI GTX460 Hawk 1gb MSI GTX460 Hawk 1gb 
RAMHard DriveHard DriveHard Drive
Kingston HyperX 8gb (2x4gb) Crucial M4 64GB Samsung F3 1TB Western Digital 320GB 
CoolingOSMonitorMonitor
Custom WC Windows 7 Ultimate X64 Dell E2311H Dell E2311H 
MonitorKeyboardPowerCase
LH 23EN43 Ducky Year of the Dragon 2012 SilverStone Strider 1000W-P Corsair 800D 
Audio
Asus Xonar Essence STX 
  hide details  
Reply
    
CPUMotherboardGraphicsGraphics
FX-8350 Asus Crosshair V MSI GTX460 Hawk 1gb MSI GTX460 Hawk 1gb 
RAMHard DriveHard DriveHard Drive
Kingston HyperX 8gb (2x4gb) Crucial M4 64GB Samsung F3 1TB Western Digital 320GB 
CoolingOSMonitorMonitor
Custom WC Windows 7 Ultimate X64 Dell E2311H Dell E2311H 
MonitorKeyboardPowerCase
LH 23EN43 Ducky Year of the Dragon 2012 SilverStone Strider 1000W-P Corsair 800D 
Audio
Asus Xonar Essence STX 
  hide details  
Reply
post #15 of 18
Code:
for (int i = 0; i < SIZE_OF_ARRAY; i++) {
cout << "Enter array value: ";
cin >> n;
                arr[i] = n;
total += n;
}
ShadowForge
(12 items)
 
Defiant
(14 items)
 
CarbonCat
(13 items)
 
CPUMotherboardGraphicsRAM
Phenom II x6 1405T (unlocked Athlon II X4 640T) ASUS M5A99X EVO AM3+ Asus ENGTX470/2DI/1280MD5/V2 16 GB (4x4GB) G.Skill DDR3 1600 CAS9 1.35v 
Hard DriveHard DriveOptical DriveCooling
WD Caviar Blue 250 2.5" Laptop Drive WD Caviar Black 1TB 3.5" Pioneer BDR-203 BluRay Burner Corsair H60 push 
OSOSMonitorPower
Windows 7 Pro x64 Ubuntu 11.10 Samsung 40" 60hz  ANTEC NEO ECO 520W 
CaseMouse
NZXT Gamma Microsoft Bluetooth Notebook Mouse 5000 
CPUMotherboardGraphicsRAM
i7 - 2600k [5.0 1.42v] ASUS P8Z68 Deluxe Sapphire HD6950 2gb Dirt 3 Edition 8GB G.Skill DDR3 2133 CAS11 
Hard DriveOSMonitorKeyboard
60GB G.Skill Sniper + 2x1TB Spinpoint F3 Raid0 Win 7 Pro x64 ASUS VW266H Razer Blackwidow 
PowerCaseMouse
Seasonic X750 Gold Corsair Carbide 500R White G9 
  hide details  
Reply
ShadowForge
(12 items)
 
Defiant
(14 items)
 
CarbonCat
(13 items)
 
CPUMotherboardGraphicsRAM
Phenom II x6 1405T (unlocked Athlon II X4 640T) ASUS M5A99X EVO AM3+ Asus ENGTX470/2DI/1280MD5/V2 16 GB (4x4GB) G.Skill DDR3 1600 CAS9 1.35v 
Hard DriveHard DriveOptical DriveCooling
WD Caviar Blue 250 2.5" Laptop Drive WD Caviar Black 1TB 3.5" Pioneer BDR-203 BluRay Burner Corsair H60 push 
OSOSMonitorPower
Windows 7 Pro x64 Ubuntu 11.10 Samsung 40" 60hz  ANTEC NEO ECO 520W 
CaseMouse
NZXT Gamma Microsoft Bluetooth Notebook Mouse 5000 
CPUMotherboardGraphicsRAM
i7 - 2600k [5.0 1.42v] ASUS P8Z68 Deluxe Sapphire HD6950 2gb Dirt 3 Edition 8GB G.Skill DDR3 2133 CAS11 
Hard DriveOSMonitorKeyboard
60GB G.Skill Sniper + 2x1TB Spinpoint F3 Raid0 Win 7 Pro x64 ASUS VW266H Razer Blackwidow 
PowerCaseMouse
Seasonic X750 Gold Corsair Carbide 500R White G9 
  hide details  
Reply
post #16 of 18
from wikipedia
Code:
int my_array[5] = {1, 2, 3, 4, 5};
for (int &x : my_array) {
    x *= 2;
}
your array has to be initialized first before you can use this notation
Note this is equivalent to a C# foreach
ShadowForge
(12 items)
 
Defiant
(14 items)
 
CarbonCat
(13 items)
 
CPUMotherboardGraphicsRAM
Phenom II x6 1405T (unlocked Athlon II X4 640T) ASUS M5A99X EVO AM3+ Asus ENGTX470/2DI/1280MD5/V2 16 GB (4x4GB) G.Skill DDR3 1600 CAS9 1.35v 
Hard DriveHard DriveOptical DriveCooling
WD Caviar Blue 250 2.5" Laptop Drive WD Caviar Black 1TB 3.5" Pioneer BDR-203 BluRay Burner Corsair H60 push 
OSOSMonitorPower
Windows 7 Pro x64 Ubuntu 11.10 Samsung 40" 60hz  ANTEC NEO ECO 520W 
CaseMouse
NZXT Gamma Microsoft Bluetooth Notebook Mouse 5000 
CPUMotherboardGraphicsRAM
i7 - 2600k [5.0 1.42v] ASUS P8Z68 Deluxe Sapphire HD6950 2gb Dirt 3 Edition 8GB G.Skill DDR3 2133 CAS11 
Hard DriveOSMonitorKeyboard
60GB G.Skill Sniper + 2x1TB Spinpoint F3 Raid0 Win 7 Pro x64 ASUS VW266H Razer Blackwidow 
PowerCaseMouse
Seasonic X750 Gold Corsair Carbide 500R White G9 
  hide details  
Reply
ShadowForge
(12 items)
 
Defiant
(14 items)
 
CarbonCat
(13 items)
 
CPUMotherboardGraphicsRAM
Phenom II x6 1405T (unlocked Athlon II X4 640T) ASUS M5A99X EVO AM3+ Asus ENGTX470/2DI/1280MD5/V2 16 GB (4x4GB) G.Skill DDR3 1600 CAS9 1.35v 
Hard DriveHard DriveOptical DriveCooling
WD Caviar Blue 250 2.5" Laptop Drive WD Caviar Black 1TB 3.5" Pioneer BDR-203 BluRay Burner Corsair H60 push 
OSOSMonitorPower
Windows 7 Pro x64 Ubuntu 11.10 Samsung 40" 60hz  ANTEC NEO ECO 520W 
CaseMouse
NZXT Gamma Microsoft Bluetooth Notebook Mouse 5000 
CPUMotherboardGraphicsRAM
i7 - 2600k [5.0 1.42v] ASUS P8Z68 Deluxe Sapphire HD6950 2gb Dirt 3 Edition 8GB G.Skill DDR3 2133 CAS11 
Hard DriveOSMonitorKeyboard
60GB G.Skill Sniper + 2x1TB Spinpoint F3 Raid0 Win 7 Pro x64 ASUS VW266H Razer Blackwidow 
PowerCaseMouse
Seasonic X750 Gold Corsair Carbide 500R White G9 
  hide details  
Reply
post #17 of 18
Thread Starter 
I think its the compiler I am using, I cannot find anything on google that says it supports this new range based for statement, ill check again in the morning, going to bed.
Next one
(15 items)
 
  
CPUMotherboardGraphicsRAM
I5 3570k Asus P8Z77-V LK N760 TF F3-10666CL9S-4GBRL 
Hard DriveHard DriveHard DriveOptical Drive
Crucial M4 Kingston SNV125-S2BD Seagate Barracuda ST31000524AS Generic HP RW 
CoolingCoolingOSMonitor
Hyper 212 Evo Fans Windows 7 Pro x64 Samsung SyncMaster 2233SW 
PowerCaseAudio
Seasonic SSR-650RM 650w Storm Trooper Triton ax 720 
  hide details  
Reply
Next one
(15 items)
 
  
CPUMotherboardGraphicsRAM
I5 3570k Asus P8Z77-V LK N760 TF F3-10666CL9S-4GBRL 
Hard DriveHard DriveHard DriveOptical Drive
Crucial M4 Kingston SNV125-S2BD Seagate Barracuda ST31000524AS Generic HP RW 
CoolingCoolingOSMonitor
Hyper 212 Evo Fans Windows 7 Pro x64 Samsung SyncMaster 2233SW 
PowerCaseAudio
Seasonic SSR-650RM 650w Storm Trooper Triton ax 720 
  hide details  
Reply
post #18 of 18
Thread Starter 
ya my compiler does not support ranged based for, I am trying to get gcc. this thread can be closed now
Next one
(15 items)
 
  
CPUMotherboardGraphicsRAM
I5 3570k Asus P8Z77-V LK N760 TF F3-10666CL9S-4GBRL 
Hard DriveHard DriveHard DriveOptical Drive
Crucial M4 Kingston SNV125-S2BD Seagate Barracuda ST31000524AS Generic HP RW 
CoolingCoolingOSMonitor
Hyper 212 Evo Fans Windows 7 Pro x64 Samsung SyncMaster 2233SW 
PowerCaseAudio
Seasonic SSR-650RM 650w Storm Trooper Triton ax 720 
  hide details  
Reply
Next one
(15 items)
 
  
CPUMotherboardGraphicsRAM
I5 3570k Asus P8Z77-V LK N760 TF F3-10666CL9S-4GBRL 
Hard DriveHard DriveHard DriveOptical Drive
Crucial M4 Kingston SNV125-S2BD Seagate Barracuda ST31000524AS Generic HP RW 
CoolingCoolingOSMonitor
Hyper 212 Evo Fans Windows 7 Pro x64 Samsung SyncMaster 2233SW 
PowerCaseAudio
Seasonic SSR-650RM 650w Storm Trooper Triton ax 720 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › MS Visual C++ 2010 Express. C++0x features