How do you write multiple lines in a .txt with recursion?

How do you write multiple lines in a .txt with recursion?

Content Index :

How do you write multiple lines in a .txt with recursion?
Tag : cpp , By : PepeM
Date : January 11 2021, 05:14 PM

help you fix your problem Im a programming student and the Engineer told us to write an algorithm using recursion for the math problem "Hanoi Towers". That is done, Im able to print the instructions on the console, but I need to write the instructions on a .txt file. I have managed to create the file and write the first line of text on it, but the rest doesn't really appear. I really need some help with this guys. , Open the fstream object from main to make things easy:
void torresdehanoi(int disco, int torre1, int torre2, int torre3, ofstream& myFile) {

    if (disco == 1) {
        myFile << "Mover disco de Torre " << torre1 << " a la torre " << torre3 << endl;
    else {
        torresdehanoi(disco - 1, torre1, torre3, torre2, myFile);
        myFile << "Mover disco de Torre " << torre1 << " a la torre " << torre3 << endl;
        torresdehanoi(disco - 1, torre2, torre1, torre3, myFile);

int main()
    ofstream myFile;

    int disco = 0, torre1 = 1, torre2 = 2, torre3 = 3;

    cout << "Con cuanteas piezas desea calcular el algoritmo?" << endl;
    cin >> disco;

    if (myFile.is_open()) {
        torresdehanoi(disco, torre1, torre2, torre3, myFile);
    return 0;

No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

How to write multiple lines in a file when this multiple lines take as a input from a JTextarea?

Tag : java , By : lhoBas
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , I take multiple lines as a input from a JTextarea, If I write it in a file, then I get that the multiple lines are write in a one line in file , Slighty better version would be :
    try {
        PrintWriter fstream = new PrintWriter(new FileWriter("log.txt"));
    } catch (IOException e1) {
        // TODO Auto-generated catch block

 for(String word : jTextAreaName.getText().split("\n"))  {    

How to write commands with multiple lines in Dockerfile while preserving the new lines?

Tag : docker , By : PepeM
Date : March 29 2020, 07:55 AM
Any of those help Start your command with $', end it with ' and use \n\ for newlines, like this:
RUN echo $'[repo] \n\
name            = YUM Repository \n\
baseurl         = https://example.com/packages/ \n\
enabled         = 1 \n\
gpgcheck        = 0' > /etc/yum.repos.d/Repo.repoxyz

Write pug array in multiple lines

Tag : javascript , By : Rb.Ridge
Date : March 29 2020, 07:55 AM
I wish did fix the issue. As suggested in https://github.com/pugjs/pug/issues/502#issuecomment-137893041
try this:
  var data = [
    ["1", "1.1"], 

In terminal CLI or shell sciprt, I want count the lines of multiple files and write the lines count on the first line at

Tag : linux , By : firebasket
Date : March 29 2020, 07:55 AM

writing multiple lines to a file using multiple fprintf statement vs con-cat multiple lines and then write to a file usi

Tag : c , By : Tamizhvendan
Date : September 28 2020, 09:00 PM
I wish this helpful for you One of the properties of stdio streams, especially when connected to files, is that they buffer input and output and then write it in large pieces. Thus, unless you've interfered with the buffering of fp, you automatically get I/O behavior similar to approach 2 from approach 1.
Furthermore, you can control the size of the buffer via setvbuf(), so if you want a 10000-byte buffer then you can ensure that, allowing an approach 1 solution with I/O semantics even more similar to your approach 2. Unless you want the concatenated string for more than just printing it, there's pretty much no reason to prefer approach 2 when approach 1 is feasible.
Related Posts Related QUESTIONS :
  • The conditional operator is not allowing the program to terminate
  • Define a c++ string as "\"
  • memcpy on __declspec naked returns unexpected bytes
  • What is the proper way to link enums with CMake?
  • is it safe to use the same mutex with lock_gard and without it in other parts of code
  • How to decode MAP Invoke messages using asn1c generated code
  • Member function with strange type causing callback function mismatch
  • Visual Studio optimisations break SDL graphical output
  • How to use less memory in Sieve_of_Eratosthenes
  • Covariance in Callback Parameters C++
  • switch may fall through (no it may not)
  • Compilation fails calling Cocoa function from C++
  • How to handle classes with differently named member functions in algorithms?
  • Convert QString to QJsonArray
  • Data exchange finished in CPropertyPage::OnOK?
  • Template member specialization in template class
  • Is it not possible to assign a struct to an index of a vector?
  • Why is empty unordered_map.find not returning end()?
  • Template argument deduction for inheriting specializations
  • dlopen undefined reference
  • Member function of class with template arguments and default arguments outside class
  • Is it possible to implement a non-owning "slightly smart" pointer on top of standard weak pointers?
  • how to configure the AcquireCredentialsHandleA correctly
  • Using private versions of global extern variables with OpenMP
  • Eigen Block wrong amount of columns and rows
  • Memory alignment rules in inheritance
  • Is nullptr falsy?
  • tm_wday returns a large integer outside 0-6 range
  • Scope a using declaration, inside a header
  • How to specify constructor's template arguments inside a new expression?
  • Sort an array via x86 Assembly (embedded in C++)?? Possible?
  • How to Replace only Part of the Variable using #define
  • How do you compare the performace of valarrays vs built-in arrays?
  • Is it normal for C++ static initialization to appear twice in the same backtrace?
  • c++ generate a good random seed for psudo random number generators
  • Why isn't my operator overloading working properly?
  • Getting meaningful error messages from fstream's in C++
  • C++: Converting Julian dates to Gregorian
  • Could someone explain this interesting behaviour with Sleep(1)?
  • Is it possible to roll a significantly faster version of modf
  • Updating pointer using signals and slots
  • How are classes more secure than structures?
  • finding "distance" between two pixel's colors
  • C++ Greatest Number Verification
  • Why does my token return NULL and how can I fix it?(c++)
  • C++ enforce conditions on inherited classes
  • what happened if an exception is not captured?
  • Redundant naming in C/C++ typedefs/structs
  • question about STL thread-safe and STL debugging
  • killing a separate thread having a socket
  • Returning the size of available virtual memory at run-time in C++
  • Parallel computing for integrals
  • How do I force my std::map to deallocate memory used?
  • C++ Templates: implicit conversion, no matching function for call to ctor
  • Adding python script to c++ project
  • C++ private pointer "leaking"?
  • Initializing Primitive Array to One Value
  • how is push_back implemented in STL vector?
  • C++ Profiling: KiFastSystemCallRet
  • Multiple rows with a single INSERT in SQLServer 2008
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com