So annoying. How to do it?

This is a discussion on So annoying. How to do it? within the C++ Programming forums, part of the General Programming Boards category; Hi, an exercise in this book im reading says, make a program that prints This (") is a quote, and ...

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    132

    So annoying. How to do it?

    Hi, an exercise in this book im reading says, make a program that prints

    This (") is a quote, and this (\) is a backslash.

    Now, they done this on purpose because when you write " it ends the string.

    Code:
    #include <iostream>
    
    int main()
    {
    std::cout <<"This (") is a quote, and this (\) is a backslash" << std::endl;
    system("PAUSE");
    return 0;
    }
    Now this don't work.

    Can someone point out how to do this because its so simple yet so annoying.

    Thanks in advance.


    Hugo.

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,581
    Have you bought this book, or downloaded it illegally too, like the VB ones?
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #3
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,077
    You have to read more deeply. What you're looking at is a section on escape characters. Since in strings quotes and backslashes have purpose, you need to qualify them with the escape sequence character, the backslash.
    Code:
    std::cout <<"This (\") is a quote, and this (\\) is a backslash" << std::endl;
    I'm sure it says that if you keep reading. Lastly, don't use system(). Pause the program with cin.get().

    Quote Originally Posted by Mario F.
    Have you bought this book, or downloaded it illegally too, like the VB ones?
    I guess a few pages got corrupted in the data transfer.
    Sent from my iPad®

  4. #4
    Registered User
    Join Date
    Apr 2006
    Posts
    132
    Mario, if you aint going to help, dont reply to my posts please.
    All i done was ask for a bit of help.

    Thanks alot sly, i didnt know about escape characters.

    Does iostream contain cin.get() ?

    Thanks alot.

    Hugo.

  5. #5
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,077
    Of course.

    It's a function of the cin object. You'll learn about that in that PDF file of yours.
    Sent from my iPad®

  6. #6
    Registered User
    Join Date
    Apr 2006
    Posts
    132
    pdf?

    Hmm, i get a compile error when i use cin.get()

    Code:
    // Exercise One
    #include <iostream>
    
    int main()
    {
    	std::cout <<"This (\") is a quote, and (\\) is a backslash" << std::endl;
    	cin.get()
    	return 0;
    }
    Error is

    Code:
    ------ Build started: Project: Exercise 1, Configuration: Debug Win32 ------
    Compiling...
    Exercise 1.cpp
    .\Exercise 1.cpp(7) : error C2065: 'cin' : undeclared identifier
    .\Exercise 1.cpp(7) : error C2228: left of '.get' must have class/struct/union
            type is ''unknown-type''
    .\Exercise 1.cpp(8) : error C2143: syntax error : missing ';' before 'return'
    Build log was saved at "file://c:\Documents and Settings\Reece.YOUR-E0367A1424\My Documents\Visual Studio 2005\Projects\Exercise 1\Exercise 1\Debug\BuildLog.htm"
    Exercise 1 - 3 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
    How come?

  7. #7
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,581
    pdf?
    chm then?
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  8. #8
    Registered User
    Join Date
    Apr 2006
    Posts
    132
    chm? what are you even on about?

  9. #9
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,581
    Look hugo... You are reading C++ Primer 4th Edition from Addison Wesley. I know the exercise in question. You will do yourself and everyone else a favor if you actually read the full chapter before asking things as trivial as those. Read. It's all there being explained to you. Why and how it works.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  10. #10
    Registered User
    Join Date
    Apr 2006
    Posts
    132
    Yes i am. I am at the end of the first chapter. now pray tell me where in that it explains this to me?

  11. #11
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,077
    Is this how you read:
    In this chapter we'll explain ho-- ---- use es---- -------- ----- -------. --- ------- ------ ----- ------ program ------ -- ------ ------ ---- ------- useful in many -----. ---- ------- ----- ----- ------- the quote(") cha----- ------ and ----- -----ckslash(\) ----------. ------- ---------- ------- -------- but you ------- --------- ----- ----- ---------. So let's look at an example program:
    Code:
    #include <ios------
    
    ------- ----- ----;
    
    ----- main() {
        std::cout << "-------- ---- -------- ---- ------- -----;
    }
    Try this for ------- --------- ------ ----- -------.
    Sent from my iPad®

  12. #12
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,581
    Trust me, son. You are not going to learn C++ if you choose to not pay attention to the details.

    What have you learned of namesapces so far on that book?... What did it teach you about the standard namespace and the #using directive?

    To avoid having you replying nothing, I'll tell you myself. It taught you that both cin and cout belong to the std namespace.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  13. #13
    Registered User
    Join Date
    Apr 2006
    Posts
    132
    Oh yeh i didnt realize. haha.

    std::cin.get();

    cheers

  14. #14
    Registered User
    Join Date
    Apr 2006
    Posts
    132
    Well, cin.get dont work on this. how come?

    Code:
    #include <iostream>
    #include <string>
    
    int main()
    {
    
    	std::cout << "Please enter your first name: ";
    
    
    	std::string Name;   
    	std::cin>>Name;   
    
    
    	std::cout << "Hello, " << Name << "!" << std::endl;
    	std::cin.get();
    	return 0;
    }

  15. #15
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Doesn't work? What do you expect it to do?

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Annoying people on-line is now a crime...
    By novacain in forum A Brief History of Cprogramming.com
    Replies: 30
    Last Post: 01-12-2006, 09:42 PM
  2. Annoying bug I can't find or fix!
    By homeyg in forum C++ Programming
    Replies: 3
    Last Post: 11-21-2004, 12:13 AM
  3. Yahoo! mail is bieng soooo annoying !!!!
    By Brain Cell in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 11-08-2004, 03:23 PM
  4. Beating stick of annoying people
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 17
    Last Post: 05-27-2004, 05:00 PM

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