Page 1 of 1

Using std::cout in V 3.0.0 for MODM7AE70

Posted: Mon Jan 21, 2019 5:29 am
by ecasey
std::cout does not do a carriage return (\r) for output in MTTTY on my Windows 10 machine.
Previous versions always did.

For the code:

Code: Select all

    while (1)    {
        OSTimeDly(TICKS_PER_SECOND);
       std::cout << "one "<<endl << "two "<< endl ;
    }
}
I get this in the MTTTY window:

Code: Select all

one
    two
        one
            two
                one
                    two
                        one
                            two
                                one
                                    two 
It std::endl seems to work fine from within a std::stream, for example, the code:

Code: Select all

    std::ostringstream Reading;
    Reading <<"one "<<std::endl << "two "<< std::endl ;
    while (1)
    {
        OSTimeDly(TICKS_PER_SECOND);
       std::cout << Reading.str() <<"three "<< std::endl ;
    }
}
gives this output:

Code: Select all

one
two
three
      one
two
three
      one
two
three
I think std::endl should be consistent between std::streams and std::cout. That would save me having to put a "\r" into every std::cout statement.

Ed

Re: Using std::cout in V 3.0.0 for MODM7AE70

Posted: Mon Jan 21, 2019 10:46 am
by pbreed
By definition in the C++ standard endl is \n....

The init call is supposed to modify stdout so \n turns into \r\n automagicall...

Is this happening after the init call?
(need to dig some more, there were some issue here and it may be broken again)

Re: Using std::cout in V 3.0.0 for MODM7AE70

Posted: Mon Jan 21, 2019 10:53 am
by ecasey
Yes it is after init() call. Here is the whole thing.

Code: Select all

void UserMain(void *pd)
{
    init();                                       // Initialize network stack
    StartHttp();                                  // Start web server, default port 80
    WaitForActiveNetwork();

    iprintf("Application: %s\r\nNNDK Revision: %s\r\n", AppName, GetReleaseTag());
    ostringstream Reading;
    Reading <<"one "<<endl << "two "<< endl ;
    while (1)
    {
        OSTimeDly(TICKS_PER_SECOND);
       std::cout << Reading.str() <<"three "<< endl ;
    }
}

Re: Using std::cout in V 3.0.0 for MODM7AE70

Posted: Mon Jan 21, 2019 5:42 pm
by pbreed
Have a fix, please submit a support ticket and I'll send you a patched file.