linux - Can't solve declaration and loop errors in C++ building with Ubuntu -
my project won't build because of these 2 errors, , have not been able figure out how fix them. 1 of them thought related version of gcc/g++, have 4.7 , i'm pretty sure c++ 11 along it. i'm not sure other "it" declaration error.
my code:
#include "stdafx.h" using namespace std; #include <iostream> #include <string> void encrypt(std::string &iostr, int key) { key %= 26; int ch; (auto &it : iostr) { ch = tolower(it); if (!islower(ch)) { continue; } ch += key; if (ch > 'z') { ch -= 26; } = ch; } } int main() { string source; int key = 1; cout << "paste cyphertext , press enter shift each letter right 1"; getline(cin, source); encrypt(source, key); cout << source << ""; encrypt(source, key); cout << source << endl; cout << "press enter exit"; cin.ignore(cin.rdbuf()->in_avail() + 1); return 0; }
errors:
test.cpp: in function ‘void encrypt(std::string&, int)’: test.cpp:10:13: error: iso c++ forbids declaration of ‘it’ no type [-fpermissive] test.cpp:10:18: error: range-based ‘for’ loops not allowed in c++98 mode
what's going on these errors, , how can fix them? in advance help, it's appreciated.
you need compiler option -std=c++11
.
and comment first header file since using gcc, think windows specific:
//#include "stdafx.h"
Comments
Post a Comment