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

post #1 of 18
Thread Starter 
I finished C++ without fear, using Microsoft Visual C++ 2010 express. I got the second edition cause I found out that the first was from 2004 (kinda outdated) and had stuff included for c++0x. I am on "ranged-based for statement" and it is not working. I googled around and it seems like MS visual supports c++0x features. so does the compiler support it or is the books code wrong?

code:

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& n : arr) {
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;
}
Errors

Quote:
1>------ Build started: Project: print1, Configuration: Release Win32 ------
1> print1.cpp
1>print1.cpp(11): error C2144: syntax error : 'int' should be preceded by ';'
1>print1.cpp(13): error C2143: syntax error : missing ',' before ':'
1>print1.cpp(13): error C2530: 'n' : references must be initialized
1>print1.cpp(13): error C2143: syntax error : missing ';' before '{'
1>print1.cpp(20): error C2143: syntax error : missing ',' before ':'
1>print1.cpp(25): error C2143: syntax error : missing ',' before ':'
1>print1.cpp(25): error C2530: 'n' : references must be initialized
1>print1.cpp(29): error C2143: syntax error : missing ',' before ':'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

EDIT: this is NOT the same as regular c++ for statement, this is a ranged-based for statement that is new in c++0x.
book:
Quote:
for(base_type& variable : container) // Reference
statement

for(base_type variable : container) // By value
statement

Edited by Droo k6 - 8/5/11 at 10:17pm
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 #2 of 18
first thing I see
int arr[SIZE_OF_ARRAY] ;
Edited by selectstriker2 - 8/5/11 at 9:59pm
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 #3 of 18
Yeah, you're missing a semicolon after

int arr[SIZE_OF_ARRAY]
Awesomesauce
(13 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i7 920 Gigabyte GA-EX58-UD5 MSI GTX570 865/2100@1.025v 3x2GB OCZ Gold DDR3-1600 
Hard DriveOSMonitorPower
1.5TB 7200RPM Windows 7 Ultimate x64 Asus 23" XFX Black Edition 750W 
Case
Raven RV02 
  hide details  
Reply
Awesomesauce
(13 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i7 920 Gigabyte GA-EX58-UD5 MSI GTX570 865/2100@1.025v 3x2GB OCZ Gold DDR3-1600 
Hard DriveOSMonitorPower
1.5TB 7200RPM Windows 7 Ultimate x64 Asus 23" XFX Black Edition 750W 
Case
Raven RV02 
  hide details  
Reply
post #4 of 18
are you using Visual Studio 2010 to write this. it should have intellisense to help debug code. I use it every day with C# which i prefer much more than c++
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 #5 of 18
Thread Starter 
Quote:
Originally Posted by selectstriker2 View Post
first thing I see
int arr[SIZE_OF_ARRAY] ;
adding that ; produces 3 additional errors

edit: 1 addional error

edit edit: 1 less error, sorry i am a little tired
Edited by Droo k6 - 8/5/11 at 10:07pm
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 #6 of 18
Quote:
Originally Posted by Droo k6 View Post
adding that ; produces 3 additional errors
because it is actually compiling further. usually VS will stop compiling after so many errors.
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 #7 of 18
curious why you are trying
for (int& n : arr) instead of

for (i; i < 10; i++)
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 #8 of 18
Thread Starter 
Quote:
Originally Posted by selectstriker2 View Post
are you using Visual Studio 2010 to write this. it should have intellisense to help debug code. I use it every day with C# which i prefer much more than c++
yes i am using visual studio 2010 to write it

Quote:
Originally Posted by selectstriker2 View Post
because it is actually compiling further. usually VS will stop compiling after so many errors.
sorry it was 1 less, counted wrong
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 #9 of 18
You also need to initialize n. Put an

int n = 0;

immediately after

int total = 0;

edit: nvm, too used to java-style foreach.
C++ has different for-each loop syntax.

for each (int n in arr){
}
Edited by iambald - 8/5/11 at 10:15pm
Awesomesauce
(13 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i7 920 Gigabyte GA-EX58-UD5 MSI GTX570 865/2100@1.025v 3x2GB OCZ Gold DDR3-1600 
Hard DriveOSMonitorPower
1.5TB 7200RPM Windows 7 Ultimate x64 Asus 23" XFX Black Edition 750W 
Case
Raven RV02 
  hide details  
Reply
Awesomesauce
(13 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i7 920 Gigabyte GA-EX58-UD5 MSI GTX570 865/2100@1.025v 3x2GB OCZ Gold DDR3-1600 
Hard DriveOSMonitorPower
1.5TB 7200RPM Windows 7 Ultimate x64 Asus 23" XFX Black Edition 750W 
Case
Raven RV02 
  hide details  
Reply
post #10 of 18
Quote:
Originally Posted by iambald View Post
You also need to initialize n. Put an

int n = 0;

immediately after

int total = 0;
this. thats why you would normally do
for (int n= 0;n<count;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
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