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
  • 212,637
  • 45
  • 247
  • 432
dato datuashvili
  • 17,789
  • 59
  • 193
  • 310
  • if anybody want post answer i will accept it – dato datuashvili Jul 10 '10 at 07:36
  • `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
  • 103,386
  • 18
  • 232
  • 318
1

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

string d="georgia is nice country"; // <-- semicolon!
In silico
  • 49,519
  • 9
  • 145
  • 141