0

I am working on a C++ program. I saw multiple lines of logs in this pattern in one of the files:

#include <iostream>

using namespace std;

int main()
{
    std::cout << "First line"
                                                " second line" << std::endl; 

    return 0;
}

I am not very familiar with cpp language, is this a standard way of logging and how does it work? I feel like it should give some kind of syntax error on a quick look?

  • That's not a comment. – eerorika May 11 '22 at 08:05
  • @eerorika my bad, updating... – backToBack May 11 '22 at 08:06
  • You may be interested in this thread: [On concatenating adjacent string literals](https://softwareengineering.stackexchange.com/questions/254984/on-concatenating-adjacent-string-literals). In short, it's a feature in the language. – rawrex May 11 '22 at 08:09
  • [How does concatenation of two string literals work?](https://stackoverflow.com/questions/12120944/how-does-concatenation-of-two-string-literals-work) and [Does the C++ standard guarantee that "a" "b" is merged to "ab"?](https://stackoverflow.com/questions/65846754/does-the-c-standard-guarantee-that-a-b-is-merged-to-ab) have some explanation. Normally you'd just put another `<<` at the beginning of the second line to make things clearer and more readable. – Retired Ninja May 11 '22 at 08:12
  • 3
    Does this answer your question? [How does concatenation of two string literals work?](https://stackoverflow.com/questions/12120944/how-does-concatenation-of-two-string-literals-work) – Jasper May 11 '22 at 14:19

1 Answers1

0

To log a simple string in C++ one can type std::cout << "My String.";

To log a variable one can replace "My String" from before with their variable.

to either add a string or another variable to a std::cout one can add "+ "My String"" or + MyVariable.

To end a line and begin writing to the line below one can add \n to their string.

To play a sound one can add \a to their string.

DischordDynne
  • 117
  • 15