-8

I can't figure out why it says this. I am new as you can probably tell... here is the code:

#include <iostream>
using namespace std
int main() {
    if (cin >> "hi"
        cout << "hello"

    return 0;
}
ElSnowman
  • 21
  • 4
  • 1
    Welcome to stackoverflow. When asking a question with a code error, it's good to explain what you want to do and include any error messages in your question so we can help you fix the problem. At the moment I can't tell what you want the code to do. `cin >> "hi"` doesn't really make sense. – eigenchris Feb 15 '15 at 01:18
  • I feel so proud of actually [improving](http://stackoverflow.com/posts/28522086/revisions) this question – sehe Feb 15 '15 at 23:14

1 Answers1

3

"The thing you were using" (read: your compiler) wanted you to end your using namespace std statement with a semicolon, not to dump one at the start of a function definition.

Your code has a number of extreme and baffling syntax errors, to the extent that it's not even clear what you're trying to accomplish.

Below is a hint to get you started but, from now on, I strongly recommend that you read a good, peer-reviewed C++ book and learn the language before asking any further questions about nonsense code!

#include <iostream>
#include <string>

using namespace std;


int main()
{
    string input;
    getline(cin, input);

    if (input == "hi") {
       cout << "hello" << endl;
    }

    return 0;
}
Community
  • 1
  • 1
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
  • Sorry, I have been reading a book from 1995 that I got from my school library and got this compiler about 30 minutes ago. I'm not sure why I called it "the thing", my brain must have gone dead right then. I don't have money to spend on a book, so whatever I guess. – ElSnowman Feb 15 '15 at 01:31
  • You should add the alternate form that will be seen when starting, using character arrays and `cin`. – David Feb 15 '15 at 03:27
  • @David: No, absolutely not, because that form _shouldn't_ be seen when starting out. – Lightness Races in Orbit Feb 15 '15 at 03:32
  • I've never seen a book not start out that way. They all start with the basics. – David Feb 15 '15 at 03:39
  • 1
    @David: Character arrays are not "the basics"; `std::string` is. Fumbling about with manual memory management and manually-bounded arrays is advanced. Unfortunately, bad books start with the advanced stuff pretending that it's the basics; however, [there are good books too](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list)! – Lightness Races in Orbit Feb 15 '15 at 15:30