Skip to content

Backslashes aren't escaped properly in Latex output #8

Description

@nahumj

Backslash characters (\\ in QBL) should become \textbackslash in Latex.

QBL content:

Both `std::cout << '\\n';` and `std::cout << std::endl;` cause a newline character to be 
emitted to standard output. Why is different about using `std::endl` to do so?
#prereq #Quiz1bSpring2026
:options=5
[*] It will also flush the stream's buffer
* It will also emit an EOF (`\\0`) character
* There isn't a difference
* `std::endl` requires non-whitespace characters to precede it 
* It will raise an exception if the stream is closed 

Wrong Latex Output generated by QBL:

\question Both \texttt{std::cout $<$$<$ '\n';} and \texttt{std::cout $<$$<$ std::endl;} cause a newline character to be \\
emitted to standard output. Why is different about using \texttt{std::endl} to do so?

\begin{mcanswerslist}
\answer[correct] It will also flush the stream's buffer
\answer It will raise an exception if the stream is closed 
\answer It will also emit an EOF (\texttt{\0}) character
\answer There isn't a difference
\answer \texttt{std::endl} requires non-whitespace characters to preceed it 
\end{mcanswerslist}

Correct Latex Output:

\question Both \texttt{std::cout $<$$<$ '\textbackslash n';} and \texttt{std::cout $<$$<$ std::endl;} cause a newline character to be \\
emitted to standard output. Why is different about using \texttt{std::endl} to do so?

\begin{mcanswerslist}
\answer[correct] It will also flush the stream's buffer
\answer It will raise an exception if the stream is closed 
\answer It will also emit an EOF (\texttt{\textbackslash 0}) character
\answer There isn't a difference
\answer \texttt{std::endl} requires non-whitespace characters to precede it 
\end{mcanswerslist}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions