Thread: Could someone explain what I did wrong with this?

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    3

    Could someone explain what I did wrong with this?

    I am totally new to any type of programing and I was hesitant in posting this question but I cannot figure out what is wrong with this I am currently reading the C++ primer plus book and I copied this code and it doesn't want to run I have know idea why it doesn't work

    Code:
    //bodini.cpp -- using escape sequences
    #include <iostream>
    using namespace std;
    int main()
    {
        cout << "\aOperation  "HyperHyde" is now activated!\n";
        cout << "Enter your agent code:_________\b\b\b\b\b\b";
        long code;
        cin >> code;
        cout << "\aYou entered " << code << " ...\n";
        cout << "\aCode verified! Proceed with Plan Z3!\n";
        cin.get();
        return 0;
    }
    the errors I am getting is this
    6 C:\Documents and Settings\Server2003\My Documents\C++ Projects\Bondini.cpp expected `;' before "HyperHyde"
    but I can't see anything wrong with it

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    You need to use an escape sequence if you want to embed the quote character in your string.

  3. #3
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    Code:
    std::cout << "Operation \"HyperHyde\" is now acrtivated!\n";
    Will also do the trick
    Double Helix STL

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> Will also do the trick
    That's exactly what I was hinting at. You used an escape sequence to solve the problem.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Indeed, but who says Paroxysm knows what an escape sequence is?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User
    Join Date
    Dec 2007
    Posts
    3
    LOL thats so funny I had thought that I copied it exactly from the book but now that you point it out I re looked ( for the umteenth time) and noticed that you are totally right I can't believe I missed that thank you peeps
    ok when I first wrote this line it was like this cout << "\aOperation "\HyperHyde"\ is now activated!\n"; I knew there was a problem in there so I thought that if I took them out which wasn't the fix to my problem at all it was a typo on my part
    Last edited by Paroxysm; 01-07-2008 at 03:05 PM.

  7. #7
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> Indeed, but who says Paroxysm knows what an escape sequence is?

    The code includes this line at the top:
    Code:
    //bodini.cpp -- using escape sequences
    Based on that, I assumed that the OP was trying to learn escape sequences, and was at least familiar with the term.

    Therefore, since the exercise appears to be meant to learn escape sequences, I think it best to not just give the answer, but instead hint at it.

    And if the OP is not familiar with escape sequences and is not doing an exercise specifically related to them, then he or she can look them up rather easily or ask for clarification here.

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Aha. I see your reasoning.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 12:40 PM
  2. pow function returns wrong value
    By ckbales in forum C Programming
    Replies: 5
    Last Post: 02-01-2003, 09:46 PM
  3. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM
  4. What's wrong with this???
    By beginner in forum C++ Programming
    Replies: 12
    Last Post: 11-25-2002, 10:52 PM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 01:04 PM