-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
  • 7
    Your code is completely nonsensical, I'm afraid. – Lightness Races in Orbit Feb 15 '15 at 01:17
  • 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
  • Looks like you were trying to code and your cat stepped on your keyboard ? – P0W 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
  • @POW What kind of cat ? – ElSnowman Feb 15 '15 at 23:18

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
  • 369,052
  • 73
  • 620
  • 1,021
  • 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
  • 2
    @ElSnowman: Standard C++ did not come into existence until 1998. You need to get yourself a book from _this_ millennium. I'm sure you can forgo alcohol for a couple of days to save up the necessary £20! And we really expect you to work at a problem for more than 30 minutes before asking us for help with it. However, I don't want to discourage you: keep trying and keep learning. Good luck! – Lightness Races in Orbit Feb 15 '15 at 01:32
  • 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