Could someone explain what I did wrong with this?

This is a discussion on Could someone explain what I did wrong with this? within the C++ Programming forums, part of the General Programming Boards category; I am totally new to any type of programing and I was hesitant in posting this question but I cannot ...

  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,328
    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,475
    Code:
    std::cout << "Operation \"HyperHyde\" is now acrtivated!\n";
    Will also do the trick
    I'm just trying to be a better person - My Name Is Earl

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,328
    >> 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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,668
    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 02:05 PM.

  7. #7
    Registered User
    Join Date
    Jan 2005
    Posts
    7,328
    >> 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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,668
    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, 08:46 PM
  3. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 11:01 AM
  4. What's wrong with this???
    By beginner in forum C++ Programming
    Replies: 12
    Last Post: 11-25-2002, 09:52 PM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 01:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21