Thread: How can I output a long text or a poem to the file from the console?

  1. #1
    Registered User
    Join Date
    Nov 2015
    Posts
    112

    How can I output a long text or a poem to the file from the console?

    How can I output a long text or a poem to the file from the console?
    How can I code, in the console entering, typing a keyboard, save a text file?
    My simplest task is to stupor.
    I do not know how this way, that a break in words would not be the end of the input.

    "Старі будинки ажурові
    І кожен камінь - вічний слід
    Давно минулої любові,
    Умерлих літ, безсмертних літ.

    Кавярні й башти, сни з явою,
    Рабле й Рембо, квітки й трава,
    І хтось усмішкою чудною
    У невідоме зазива.

    Фіалки, привиди Версалю
    І кармін губ, і пяний шлюб,
    І терпкощі чудного балю
    Крізь яд скрипок і тугу труб.

    Ти випив самогону з кварти
    І біля діжки в бруду спиш,
    А там десь голуби, мансарди,
    Поети, сонце і Париж!
    "

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,722
    C++ has a standard function named getline(). It takes an input stream, a string and (optionally) a delimiter. If you use '\"' as the delimiter, it'll keep reading until it encounters double-quotes. Then you could take that string and save it in a file normally.
    Devoted my life to programming...

  3. #3
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    From the way they phrased it, it almost sounds like they just need to type `echo "blah" > my_filename.txt`

  4. #4
    Registered User
    Join Date
    Nov 2015
    Posts
    112
    Thanks!!

    Code:
    for(int i=0; i<50*50; i++)
              {
                  std::cin >> s[i];
                  if (s[i]=="@")goto M1;
    
              }
           M1:
            std::cout << s << std::endl;
    What is wrong with this particular cycle?

  5. #5
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,608
    I wouldn't do it like that. You don't need to write loops like this.

    Code:
    string s;
    if (getline(cin, s, '@')) {
       cout << s << endl;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Text Justification for console output
    By greywolf0723 in forum C++ Programming
    Replies: 1
    Last Post: 03-10-2009, 12:29 AM
  2. Output string to both console and file at the same time
    By GOBLIN-85 in forum C++ Programming
    Replies: 6
    Last Post: 11-04-2008, 06:52 AM
  3. How do you output the contents of a console screen to file?
    By Finchie_88 in forum C++ Programming
    Replies: 2
    Last Post: 03-31-2005, 08:26 AM
  4. Console Text RPG- File I/O and Inventory
    By Jontay in forum Game Programming
    Replies: 17
    Last Post: 11-23-2003, 02:37 AM
  5. Recording console window output to a text file?
    By HolySmiter in forum C++ Programming
    Replies: 3
    Last Post: 02-24-2002, 03:13 PM

Tags for this Thread