user466534
user466534

Reputation:

question on string iterators

I have following code

#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(){
  string d="georgia is nice country":
  string::iterator my;
  for (my=d.begin();my!=d.end();my++) {
    cout<<*my<<endl;
  }
  return 0;
}

but it causes a compiler error saying "my is undefined". What is wrong?

Upvotes: 0

Views: 71

Answers (2)

In silico
In silico

Reputation: 52159

You need to put a semicolon instead of a colon after the string.

string d="georgia is nice country"; // <-- semicolon!

Upvotes: 1

Praetorian
Praetorian

Reputation: 109119

string d="georgia is nice country"; // <-- semicolon, not colon

Upvotes: 1

Related Questions