How to remove error in for each command?

Pages: 12
How should to remove error in for each command? I try to find alternative to foreach command (e.g. in php) and parse vector of strings.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// proccessing_args.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <vector>
#include <string>
#include <iostream>
#include <conio.h>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
	vector<string> cities;
    cities.push_back("Seattle");
    cities.push_back("Los Angeles");

    // Use C++ "for each" construct syntax
    // to iterate over "cities" vector
    for each(string& city in cities)
    {
        cout << city << endl;
    }
_getch();
	return 0;
}


proccessing_args.cpp
proccessing_args\proccessing_args.cpp(20): error C2440: 'initializing' : cannot convert from 'const std::basic_string<_Elem,_Traits,_Ax>' to 'std::string &'
with
[
_Elem=char,
_Traits=std::char_traits<char>,
_Ax=std::allocator<char>
]
Conversion loses qualifiers
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
It is incorrect syntax.
Corect syntax for range-based-for loops:
1
2
3
for(const std::string& city: cities) { //or for(const auto& city: cities)
    std::cout << city << '\n';
}
Thanks for advice. This was original code which I had, but I got and am getting this error now:

1
2
3
proccessing_args.cpp(20): error C2143: syntax error : missing ',' before ':'
proccessing_args.cpp(20): error C2530: 'city' : references must be initialized
proccessing_args\proccessing_args.cpp(20): error C2143: syntax error : missing ';' before '{'


I am using C++Visual studio 2010 Express and I think it is C++ 11.
C++Visual studio 2010 Express was released in 2010. Final version of C++11 standard was released in 2011. Do the math.
I suggest you to upgrade to VS 2013 Express. There is littke reason to not upgrade to newer version when it is avaiable.
Is it possible to have installed both versions? May I ask you how much it takes disk space? I have max. 11 Gb of disk space avalaible for programs.
Is it possible to have installed both versions?
It is possible, but unsupported. VS2010 is outdated and today most people on this site uses C++11 so you are won't be able to use majority of answers here with it.

May I ask you how much it takes disk space?
MS lists space reqirement for
Express 2013 for Windows Desktop as 5 GB of disc space.
I have updated the program, but I cannot find where it has been installed. It is suspicious. The installation took just few seconds and they did not ask me where I want to install it!
Did you download installer from http://www.visualstudio.com ?
It will be a net installer which downloads and installs required elements itself.
Instalation routine would be same as for 2010 version

Edit: or from http://www.microsoft.com/en-us/download/details.aspx?id=40787
Last edited on
I downloaded from Microsoft:
http://www.microsoft.com/en-us/download/confirmation.aspx?id=40784

They written I need 5 GB of available hard disk space but my system disk space is only 300Mb. And Programs disk space is 10Gb free. But if they need 5 GB so some proccess should take at least minutes and not seconds. The file I installed was: vcredist_x86.exe having 6.3 Mb
Why they did not ask me for registration key during instalation? I have RK from the time of installation of VS C++ 2010
It is not Visual Studio. It is a bunch of libraries which are required by some programs.
I have posted links to the actual installation.
As Visual Studio deeply integrates with OS, it requires some libraries to be installed on system disc. You should have most of them installed already, like .NET4 (if not, it is another 1 GB).

Express versions of VS are free and does not require a key

You might swithc compiler say to code::blocks or Orwell Dev C++. Which have C++11 support and more lightweight.



By the way 300 mb on system disc is too little: simple NVidia drivers update requires at least 1.4 GB to be free
Last edited on
I am trying to install it. Gray window with title "Express 2013 for Windows Desktop" appeared. But nothing happens. I wait some time. My cpu performance is at cca3-4%. Nothing happens. I try to click on the Window but nothing happens. Only button that works is the minimize button. I cannot focus close button or arrow image. This is how the window looks but it does not have any text or buttons under the title:

[img]http://i.stack.imgur.com/lGtqG.png[/img]
One of the possibilities: You downloaded VS for windows, not Windows Desktop
Second: You are using either XP of windows 7 without 1st service pack
If you are ussing win XP, only thing you can do is to get alternative compiler.
I have downloaded VS for Windows desktop but my VS 2010 is VS for Windows. So I need the VS for Windows, no desktop?
Second one is correct, but it works only on Windows 8.1. If you have Windows 7, you need VS for Windows desctop.
I have XP. I downloaded instalaton 40748 and it does not work. Same problem like before. They don't do system version check.
MiiNiPaa wrote:
If you are ussing win XP, only thing you can do is to get alternative compiler.
No visual studio studio with C++11 support is avaliable on XP. You should get alternative compiler instead.
I found:
http://msdn.microsoft.com/en-us/library/jj851139.aspx


Configuring C++ 11 Programs for Windows XP
Visual Studio 2013
Other Versions
2 out of 7 rated this helpful - Rate this topic

By installing Visual Studio 2012 Update 1, you can use the C++11 language enhancements, compilers, libraries, and other features of Visual Studio 2012 to create apps that target Windows XP and Windows Server 2003, in addition to the operating systems that are already supported.
that target Windows XP
That means those compiled programs will launch on XP, not that IDE itself will work there.
Pages: 12