This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/56498] New: invalid declaration of string iterator on comma separated list
- From: "hgkamath at hotmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 01 Mar 2013 17:19:35 +0000
- Subject: [Bug c++/56498] New: invalid declaration of string iterator on comma separated list
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56498
Bug #: 56498
Summary: invalid declaration of string iterator on comma
separated list
Classification: Unclassified
Product: gcc
Version: 4.7.2
Status: UNCONFIRMED
Severity: minor
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: hgkamath@hotmail.com
Trying to declare and initialize two iterators in a comma separated list
results in an invalid declaration error.
workaround, declare the iterator before the for statement.
a.cpp: In function âbool ispalindrome(std::string&)â:
a.cpp:7:37: error: invalid declaration of
âstd::basic_string<char>::reverse_iteratorâ
a.cpp:7:62: error: expected â;â before âi2â
a.cpp:7:62: error: âi2â was not declared in this scope
a.cpp:7:89: error: expected â)â before â;â token
a.cpp:7:92: error: âi1â was not declared in this scope
a.cpp:7:98: error: âi2â was not declared in this scope
a.cpp:7:102: error: expected â;â before â)â token
#include <iostream>
#include <string>
using namespace std;
bool ispalindrome(string &s){
// replace with below line to see the error.
// for(string::iterator i1=s.begin(),string::reverse_iterator i2=s.rbegin() ;
i1!=s.end(); i1++, i2++) {
string::reverse_iterator i2=s.rbegin();
for(string::iterator i1=s.begin() ; i1!=s.end(); i1++, i2++) {
if (*i1!=*i2) return false;
}
return true;
}
int main()
{
string s;
cin >> s ;
if (ispalindrome(s)) {
cout << "First\n";
}else{
cout << "Second\n";
}
return 0;
}