Skip to content

Instantly share code, notes, and snippets.

@tomthorogood
Last active December 11, 2015 12:28
Show Gist options
  • Save tomthorogood/4600571 to your computer and use it in GitHub Desktop.
Save tomthorogood/4600571 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
using std::cout;
using std::endl;
using std::string;
int main() {
string var1 = "butt";
string var2 = "soap";
string var3 = "orcs";
string var4 = "cyanide";
// The endl method is more C++, and is better to be in the habit of.
// Without 'end', all of this would be on one line.
cout << "Ian smells like " << var1 << endl
<< " but Iris smells like " << var2 << endl
<< " but that's okay because neither of them smell like " << var3
<< " and don't get me started on emus, which remind me of " << var4;
// But this works almost the same
cout << "Ian smells like " << var1 << "\n"
<< " but Iris smells like " << var2 << "\n"
<< " but that's okay because neither of them smell like " << "\n"
<< " and don't get me started on emus, which remind me of " << var4 << "\n";
/* The difference is that 'endl' flushes the output buffer, meaning
* the text will be displayed RIGHT NOW, whereas \n will only display
* the text after the output buffer is flushed, over which you have little
* control. This can be a pain if you're using output buffer to debug, and
* the messages are delayed and you don't actually know where your program is breaking.
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment