...not declared in this scope

I'm a newbie and I've been reading C++ All in one for dummies 2nd Edition and the 'Hello World' program works fine, but when I type this (directly copied from the book), I get the error below. I've tried the code in Geany and CodeBlocks:

main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>

using namespace std;

int main()

{
    string mystring;
    mystring = “Hello there”;
    cout << mystring << endl;
    return 0;
}



1
2
3
4
5
6
7
8
9
10
user@user-G73Sw:~/projects/GeanyProject$ /bin/sh ./geany_run_script.sh
main.cpp:9:5: error: stray ‘\342’ in program
main.cpp:9:5: error: stray ‘\200’ in program
main.cpp:9:5: error: stray ‘\234’ in program
main.cpp:9:5: error: stray ‘\342’ in program
main.cpp:9:5: error: stray ‘\200’ in program
main.cpp:9:5: error: stray ‘\235’ in program
main.cpp: In function ‘int main()’:
main.cpp:9:19: error: ‘Hello’ was not declared in this scope
main.cpp:9:25: error: expected ‘;’ before ‘there’

closed account (Gz64jE8b)
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>

using namespace std;

int main()

{
    string mystring = "Hello there";
    cout << mystring << endl;
    return 0;
}


You should have string mystring = "xxx";
instead of:

1
2
string mystring;
mystring = "xxx";
Last edited on
Thank you Mohammed for the quick response. That worked beautifully.

I found out what the problem was: I have the .pdf book and it seems to use the incorrect quotes that look like this: ”text”, as opposed the the quotes that work that should be like this: "text" ... so when I copied the text over from the .pdf book to my IDE it wouldn't run until I fixed the quotes.

Btw, I heard on Amazon from a reviewer that this book was written in 2003 and is outdated. Does anyone know if that is true?

closed account (EvoTURfi)
@carebearboy

I checked out the official site for the book and it apparently says that it was published in 2009, so it should be up to date.

http://www.dummies.com/store/product/C-All-In-One-Desk-Reference-For-Dummies-2nd-Edition.productCd-0470317353.html
closed account (Gz64jE8b)
A 2003/2009 book is perfectly OK the latest standard for C++ was released in '05 so it's not really out of date.

C++0x is arriving some time this year you may want to consider buying a new book updated for that.
Whats c++0x?
The best thing that happened to C++ in years (mainly because it's the only thing):
http://en.wikipedia.org/wiki/C%2B%2B0x
New version? Does that mean I need to relearn everything I know?
closed account (Gz64jE8b)
Ziodice, no there's just new features being added.
@carebearboy

I checked out the official site for the book and it apparently says that it was published in 2009, so it should be up to date.

http://www.dummies.com/store/product/C-All-In-One-Desk-Reference-For-Dummies-2nd-Edition.productCd-0470317353.html

Thanks for looking that up.

A 2003/2009 book is perfectly OK the latest standard for C++ was released in '05 so it's not really out of date.

C++0x is arriving some time this year you may want to consider buying a new book updated for that.

I will likely do that, so far am enjoying the for dummies book.
Last edited on
Topic archived. No new replies allowed.