Need Help Getting New Line When Writing to FileHow do I alter this tokenization process to work on a text file with multiple lines?writing files and dirs using C++Read file line by line using ifstream in C++Memory leak in my custom streambuf classC++ std::string length() or size() not working on method argsofstream is open, but does not writeC++ help regarding class implementation and writing into a created text fileWhat can I do to not use !openFile.eof()?Iterating values into a vector while reading in a file using getlinestd::ofstream won't write to file (sometimes)

Is counterpoint still used today?

What can I, as a user, do about offensive reviews in App Store?

What language is software running on the ISS written in?

Preventing Employees from either switching to Competitors or Opening Their Own Business

How to return a security deposit to a tenant

Impedance ratio vs. SWR

Are there any important biographies of nobodies?

Do height-balanced binary trees have logarithmic depth?

What is the actual quality of machine translations?

1980s live-action movie where individually-coloured nations on clouds fight

How does an ordinary object become radioactive?

Fixing obscure 8080 emulator bug?

Arriving at the same result with the opposite hypotheses

An average heaven where everyone has sexless golden bodies and is bored

Is the term 'open source' a trademark?

When conversion from Integer to Single may lose precision

Passing multiple files through stdin (over ssh)

How to tell your grandparent to not come to fetch you with their car?

Generate a Graeco-Latin square

eval() in Lightning Web Components

Trapping Rain Water

Why would future John risk sending back a T-800 to save his younger self?

How did old MS-DOS games utilize various graphic cards?

Is it a problem if <h4>, <h5> and <h6> are smaller than regular text?



Need Help Getting New Line When Writing to File


How do I alter this tokenization process to work on a text file with multiple lines?writing files and dirs using C++Read file line by line using ifstream in C++Memory leak in my custom streambuf classC++ std::string length() or size() not working on method argsofstream is open, but does not writeC++ help regarding class implementation and writing into a created text fileWhat can I do to not use !openFile.eof()?Iterating values into a vector while reading in a file using getlinestd::ofstream won't write to file (sometimes)






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








-2















I have the endl, but its not going into my file, so when I enter in more than 1 line, its all on the same line in the notepad.



I've tried:



codeFile << codeLine;
codeFile << endl;



I've also tried adding a "n" to the string by adding a constant string to it but it doesn't work.



//Writing Coded Lines to File:
if(codeFile)

//Relaying Feedback to User:
cout << "File has been successfully opened/created" << endl;
cout << "nWriting to file..." << endl;

for(int i = 0; i < lines; i++)

//Getting Non-Coded Line from User:
cin.ignore(std::numeric_limits<std::streamsize>::max(), 'n');
cin.getline(line, length);

//Creating Copy of Line:
strcpy(cline, line);

//Gathering Line Length:
length = strlen(line);

//Coding Line:
codedLine = code(length, line, cline, sAlphabet);

//Coded Line Test
cout << codedLine;

//Writing to File:
codeFile << codedLine << endl;



//Closing File:
codeFile.close();

cout << "nFile has now been closed";
}









share|improve this question






















  • You wouldn't happen to be using cygwn would you?

    – user4581301
    Mar 24 at 17:18











  • If you talk about Windows notepad.exe that only breaks lines at "rn" but that's a visual thing related to the application. Your new line character is still present. Also, don't use std::endl, use 'n' instead.

    – Timo
    Mar 24 at 17:19












  • I am using cygwin. But I'll try that.

    – Christian Martinez
    Mar 24 at 17:21











  • It worked, thank you! "/r/n"

    – Christian Martinez
    Mar 24 at 17:49

















-2















I have the endl, but its not going into my file, so when I enter in more than 1 line, its all on the same line in the notepad.



I've tried:



codeFile << codeLine;
codeFile << endl;



I've also tried adding a "n" to the string by adding a constant string to it but it doesn't work.



//Writing Coded Lines to File:
if(codeFile)

//Relaying Feedback to User:
cout << "File has been successfully opened/created" << endl;
cout << "nWriting to file..." << endl;

for(int i = 0; i < lines; i++)

//Getting Non-Coded Line from User:
cin.ignore(std::numeric_limits<std::streamsize>::max(), 'n');
cin.getline(line, length);

//Creating Copy of Line:
strcpy(cline, line);

//Gathering Line Length:
length = strlen(line);

//Coding Line:
codedLine = code(length, line, cline, sAlphabet);

//Coded Line Test
cout << codedLine;

//Writing to File:
codeFile << codedLine << endl;



//Closing File:
codeFile.close();

cout << "nFile has now been closed";
}









share|improve this question






















  • You wouldn't happen to be using cygwn would you?

    – user4581301
    Mar 24 at 17:18











  • If you talk about Windows notepad.exe that only breaks lines at "rn" but that's a visual thing related to the application. Your new line character is still present. Also, don't use std::endl, use 'n' instead.

    – Timo
    Mar 24 at 17:19












  • I am using cygwin. But I'll try that.

    – Christian Martinez
    Mar 24 at 17:21











  • It worked, thank you! "/r/n"

    – Christian Martinez
    Mar 24 at 17:49













-2












-2








-2


0






I have the endl, but its not going into my file, so when I enter in more than 1 line, its all on the same line in the notepad.



I've tried:



codeFile << codeLine;
codeFile << endl;



I've also tried adding a "n" to the string by adding a constant string to it but it doesn't work.



//Writing Coded Lines to File:
if(codeFile)

//Relaying Feedback to User:
cout << "File has been successfully opened/created" << endl;
cout << "nWriting to file..." << endl;

for(int i = 0; i < lines; i++)

//Getting Non-Coded Line from User:
cin.ignore(std::numeric_limits<std::streamsize>::max(), 'n');
cin.getline(line, length);

//Creating Copy of Line:
strcpy(cline, line);

//Gathering Line Length:
length = strlen(line);

//Coding Line:
codedLine = code(length, line, cline, sAlphabet);

//Coded Line Test
cout << codedLine;

//Writing to File:
codeFile << codedLine << endl;



//Closing File:
codeFile.close();

cout << "nFile has now been closed";
}









share|improve this question














I have the endl, but its not going into my file, so when I enter in more than 1 line, its all on the same line in the notepad.



I've tried:



codeFile << codeLine;
codeFile << endl;



I've also tried adding a "n" to the string by adding a constant string to it but it doesn't work.



//Writing Coded Lines to File:
if(codeFile)

//Relaying Feedback to User:
cout << "File has been successfully opened/created" << endl;
cout << "nWriting to file..." << endl;

for(int i = 0; i < lines; i++)

//Getting Non-Coded Line from User:
cin.ignore(std::numeric_limits<std::streamsize>::max(), 'n');
cin.getline(line, length);

//Creating Copy of Line:
strcpy(cline, line);

//Gathering Line Length:
length = strlen(line);

//Coding Line:
codedLine = code(length, line, cline, sAlphabet);

//Coded Line Test
cout << codedLine;

//Writing to File:
codeFile << codedLine << endl;



//Closing File:
codeFile.close();

cout << "nFile has now been closed";
}






c++ filestream fstream ofstream






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 24 at 17:06









Christian MartinezChristian Martinez

61




61












  • You wouldn't happen to be using cygwn would you?

    – user4581301
    Mar 24 at 17:18











  • If you talk about Windows notepad.exe that only breaks lines at "rn" but that's a visual thing related to the application. Your new line character is still present. Also, don't use std::endl, use 'n' instead.

    – Timo
    Mar 24 at 17:19












  • I am using cygwin. But I'll try that.

    – Christian Martinez
    Mar 24 at 17:21











  • It worked, thank you! "/r/n"

    – Christian Martinez
    Mar 24 at 17:49

















  • You wouldn't happen to be using cygwn would you?

    – user4581301
    Mar 24 at 17:18











  • If you talk about Windows notepad.exe that only breaks lines at "rn" but that's a visual thing related to the application. Your new line character is still present. Also, don't use std::endl, use 'n' instead.

    – Timo
    Mar 24 at 17:19












  • I am using cygwin. But I'll try that.

    – Christian Martinez
    Mar 24 at 17:21











  • It worked, thank you! "/r/n"

    – Christian Martinez
    Mar 24 at 17:49
















You wouldn't happen to be using cygwn would you?

– user4581301
Mar 24 at 17:18





You wouldn't happen to be using cygwn would you?

– user4581301
Mar 24 at 17:18













If you talk about Windows notepad.exe that only breaks lines at "rn" but that's a visual thing related to the application. Your new line character is still present. Also, don't use std::endl, use 'n' instead.

– Timo
Mar 24 at 17:19






If you talk about Windows notepad.exe that only breaks lines at "rn" but that's a visual thing related to the application. Your new line character is still present. Also, don't use std::endl, use 'n' instead.

– Timo
Mar 24 at 17:19














I am using cygwin. But I'll try that.

– Christian Martinez
Mar 24 at 17:21





I am using cygwin. But I'll try that.

– Christian Martinez
Mar 24 at 17:21













It worked, thank you! "/r/n"

– Christian Martinez
Mar 24 at 17:49





It worked, thank you! "/r/n"

– Christian Martinez
Mar 24 at 17:49












1 Answer
1






active

oldest

votes


















1














Cygwin mocks a POSIX system and uses Unix line endings, not the Windows line endings understood by NotePad.



Replacing endl with 'n' won't help. endl is a 'n' followed by a stream flush.



The best option is to use a different file reader, WordPad for example, that understands Unix line endings. The alternatives are to



  • Change your compiler toolchain to one that is not emulating a POSIX operating system, or

  • Brute force a Windows line ending with rn, but this means your code will have a similar wrong line-ending problem on a Unix -based system.





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55326312%2fneed-help-getting-new-line-when-writing-to-file%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Cygwin mocks a POSIX system and uses Unix line endings, not the Windows line endings understood by NotePad.



    Replacing endl with 'n' won't help. endl is a 'n' followed by a stream flush.



    The best option is to use a different file reader, WordPad for example, that understands Unix line endings. The alternatives are to



    • Change your compiler toolchain to one that is not emulating a POSIX operating system, or

    • Brute force a Windows line ending with rn, but this means your code will have a similar wrong line-ending problem on a Unix -based system.





    share|improve this answer



























      1














      Cygwin mocks a POSIX system and uses Unix line endings, not the Windows line endings understood by NotePad.



      Replacing endl with 'n' won't help. endl is a 'n' followed by a stream flush.



      The best option is to use a different file reader, WordPad for example, that understands Unix line endings. The alternatives are to



      • Change your compiler toolchain to one that is not emulating a POSIX operating system, or

      • Brute force a Windows line ending with rn, but this means your code will have a similar wrong line-ending problem on a Unix -based system.





      share|improve this answer

























        1












        1








        1







        Cygwin mocks a POSIX system and uses Unix line endings, not the Windows line endings understood by NotePad.



        Replacing endl with 'n' won't help. endl is a 'n' followed by a stream flush.



        The best option is to use a different file reader, WordPad for example, that understands Unix line endings. The alternatives are to



        • Change your compiler toolchain to one that is not emulating a POSIX operating system, or

        • Brute force a Windows line ending with rn, but this means your code will have a similar wrong line-ending problem on a Unix -based system.





        share|improve this answer













        Cygwin mocks a POSIX system and uses Unix line endings, not the Windows line endings understood by NotePad.



        Replacing endl with 'n' won't help. endl is a 'n' followed by a stream flush.



        The best option is to use a different file reader, WordPad for example, that understands Unix line endings. The alternatives are to



        • Change your compiler toolchain to one that is not emulating a POSIX operating system, or

        • Brute force a Windows line ending with rn, but this means your code will have a similar wrong line-ending problem on a Unix -based system.






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 24 at 17:50









        user4581301user4581301

        21.8k52035




        21.8k52035



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55326312%2fneed-help-getting-new-line-when-writing-to-file%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Obelisk of Theodosius Contents History Description Notes Bibliography Further reading External links Navigation menuAge of spirituality : late antique and early Christian art, third to seventh centuryOver 60 picturesObelisks of the World41°00′21.24″N 28°58′31.43″E / 41.0059000°N 28.9753972°E / 41.0059000; 28.97539727724550-7235741376235741376

            밀양 대씨 역사 각주 함께 보기 둘러보기 메뉴밀양 대씨

            1973년 목차 사건 문화 탄생 사망 노벨상 달력 둘러보기 메뉴