0

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?

sbi
  • 219,715
  • 46
  • 258
  • 445
  • `using namespace std;` This is saving you to type five characters every time you type an identifier from the standard library. See [this answer](http://stackoverflow.com/questions/2879555/c-stl-how-to-write-wrappers-for-cout-cerr-cin-and-endl/2880136#2880136) for why this is _not_ a good idea. – sbi Jul 10 '10 at 10:09

2 Answers2

1
string d="georgia is nice country"; // <-- semicolon, not colon
Praetorian
  • 106,671
  • 19
  • 240
  • 328
1

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

string d="georgia is nice country"; // <-- semicolon!
In silico
  • 51,091
  • 10
  • 150
  • 143