Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Simplifying new lines...

Simplifying new lines...

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
9 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MoboTech
    wrote on last edited by
    #1

    When I apply new lines, I feel that there's got to be a more easier and byte consuming way of making new lines. I'm new to the programming scene, so much help is appreciated. Instead of applying cout and endl beside every line, is there a more common and better way of doing this? Please offer advice. Thank you. Here's my code: // Lyrics.cpp : Displaying Lyrics. // Steve Baker #include "stdafx.h" #include using namespace std; int _tmain(int argc, _TCHAR* argv[]) { cout << "'Gone Crazy'" << endl; cout << "by Alan Jackson" << endl; cout << endl; cout << "Here I am all alone again tonight" << endl; cout << "In this old empty house" << endl; cout << "It's hard to learn what you don't think you need" << endl; cout << "You can't live without" << endl; cout << "Never leave the sound of the telephone" << endl; cout << "But ever since you left" << endl; cout << "I've been gone" << endl; cout << "Gone carzy, goin' out of my mind" << endl; cout << "I've asked myself the reasons," << endl; cout << "at least least thousand times," << endl; cout << endl; cout << "Press the Enter key to continue..."; cin.ignore(99,'\n'); return 0; }

    B 2 Replies Last reply
    0
    • M MoboTech

      When I apply new lines, I feel that there's got to be a more easier and byte consuming way of making new lines. I'm new to the programming scene, so much help is appreciated. Instead of applying cout and endl beside every line, is there a more common and better way of doing this? Please offer advice. Thank you. Here's my code: // Lyrics.cpp : Displaying Lyrics. // Steve Baker #include "stdafx.h" #include using namespace std; int _tmain(int argc, _TCHAR* argv[]) { cout << "'Gone Crazy'" << endl; cout << "by Alan Jackson" << endl; cout << endl; cout << "Here I am all alone again tonight" << endl; cout << "In this old empty house" << endl; cout << "It's hard to learn what you don't think you need" << endl; cout << "You can't live without" << endl; cout << "Never leave the sound of the telephone" << endl; cout << "But ever since you left" << endl; cout << "I've been gone" << endl; cout << "Gone carzy, goin' out of my mind" << endl; cout << "I've asked myself the reasons," << endl; cout << "at least least thousand times," << endl; cout << endl; cout << "Press the Enter key to continue..."; cin.ignore(99,'\n'); return 0; }

      B Offline
      B Offline
      bob16972
      wrote on last edited by
      #2

      put the text in a file. read each line of the file in a loop and spit it out onto the console with cout. Much less typing ;)

      M 1 Reply Last reply
      0
      • B bob16972

        put the text in a file. read each line of the file in a loop and spit it out onto the console with cout. Much less typing ;)

        M Offline
        M Offline
        MoboTech
        wrote on last edited by
        #3

        I need to print all my lines on one paper (hw assignment). So I don't think putting the text in a file is optional at the moment. I remember my professor giving shortcuts but forgot what he did. Any ideas?

        M 1 Reply Last reply
        0
        • M MoboTech

          I need to print all my lines on one paper (hw assignment). So I don't think putting the text in a file is optional at the moment. I remember my professor giving shortcuts but forgot what he did. Any ideas?

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          Then how about... Type one line like this: cout << "" << endl; Select the line, Ctrl-C to copy to clipboard, Ctrl-V to copy it a couple hundred times. Navigate to the top line and start typing text between the quotes. :beer: Mark

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          M 1 Reply Last reply
          0
          • M Mark Salsbery

            Then how about... Type one line like this: cout << "" << endl; Select the line, Ctrl-C to copy to clipboard, Ctrl-V to copy it a couple hundred times. Navigate to the top line and start typing text between the quotes. :beer: Mark

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            M Offline
            M Offline
            MoboTech
            wrote on last edited by
            #5

            lol I didn't mean that kind of shortcut. But I think I've figured it out, instead of using endl, I now use \n for new line. But what's the difference between endl and \n? Which should I use for this situation?

            M D S 3 Replies Last reply
            0
            • M MoboTech

              lol I didn't mean that kind of shortcut. But I think I've figured it out, instead of using endl, I now use \n for new line. But what's the difference between endl and \n? Which should I use for this situation?

              M Offline
              M Offline
              Mark Salsbery
              wrote on last edited by
              #6

              MoboTech wrote:

              But what's the difference between endl and \n?

              endl writes a '\n' to the stream AND flushes the stream. You could do cout.flush(); after you've written the lines of text. Mark

              Mark Salsbery Microsoft MVP - Visual C++ :java:

              1 Reply Last reply
              0
              • M MoboTech

                lol I didn't mean that kind of shortcut. But I think I've figured it out, instead of using endl, I now use \n for new line. But what's the difference between endl and \n? Which should I use for this situation?

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #7

                MoboTech wrote:

                But what's the difference between endl and \n?

                In a word...caching.


                "A good athlete is the result of a good and worthy opponent." - David Crow

                "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                1 Reply Last reply
                0
                • M MoboTech

                  lol I didn't mean that kind of shortcut. But I think I've figured it out, instead of using endl, I now use \n for new line. But what's the difference between endl and \n? Which should I use for this situation?

                  S Offline
                  S Offline
                  songjacky
                  wrote on last edited by
                  #8

                  void cout (char* szMsg) { cout << szMsg << endl; } cout("abc");

                  1 Reply Last reply
                  0
                  • M MoboTech

                    When I apply new lines, I feel that there's got to be a more easier and byte consuming way of making new lines. I'm new to the programming scene, so much help is appreciated. Instead of applying cout and endl beside every line, is there a more common and better way of doing this? Please offer advice. Thank you. Here's my code: // Lyrics.cpp : Displaying Lyrics. // Steve Baker #include "stdafx.h" #include using namespace std; int _tmain(int argc, _TCHAR* argv[]) { cout << "'Gone Crazy'" << endl; cout << "by Alan Jackson" << endl; cout << endl; cout << "Here I am all alone again tonight" << endl; cout << "In this old empty house" << endl; cout << "It's hard to learn what you don't think you need" << endl; cout << "You can't live without" << endl; cout << "Never leave the sound of the telephone" << endl; cout << "But ever since you left" << endl; cout << "I've been gone" << endl; cout << "Gone carzy, goin' out of my mind" << endl; cout << "I've asked myself the reasons," << endl; cout << "at least least thousand times," << endl; cout << endl; cout << "Press the Enter key to continue..."; cin.ignore(99,'\n'); return 0; }

                    B Offline
                    B Offline
                    bob16972
                    wrote on last edited by
                    #9

                    // Lyrics.cpp : Displaying Lyrics. // Steve Baker #include "stdafx.h" char* stuff[]= { {"'Gone Crazy'"}, {"by Alan Jackson"}, {""}, {"Here I am all alone again tonight"}, {"In this old empty house"}, {"It's hard to learn what you don't think you need"}, {"You can't live without"}, {"Never leave the sound of the telephone"}, {"But ever since you left"}, {"I've been gone"}, {"Gone carzy, goin' out of my mind"}, {"I've asked myself the reasons,"}, {"at least least thousand times,"}, {""} }; char otherStuff[]={ "\ 'Gone Crazy'\n\ by Alan Jackson\n\ \n\ Here I am all alone again tonight\n\ In this old empty house\n\ It's hard to learn what you don't think you need\n\ You can't live without\n\ Never leave the sound of the telephone\n\ But ever since you left\n\ I've been gone\n\ Gone carzy, goin' out of my mind\n\ I've asked myself the reasons,\n\ at least least thousand times,\n\ \n" }; using namespace std; int _tmain(int argc, _TCHAR* argv[]) { int nCount=(sizeof(stuff)/sizeof(char*)); // One way... for (int i=0;i

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups