• 12
• 9
• 9
• 13
• 10

# Very Silly Question

This topic is 4436 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I feel slow lol, but I just bought C++ Primer and I can't even get my first program to run. #include <iostream> int main() { std::cout << "Enter 2 Numbers:" << std::end1; int v1, v2; std::cin >> v1 >> v2; std::cout << "The sum of " << v1 << " and " << v2 << " is " << v1+v2 << std::end1; return 0; } When I try to compile it gives me the error : end1' undeclared in namespace std' Can someone quickly tell me whats wrong lol?

##### Share on other sites
It's 'endl', as in endline.

##### Share on other sites
That is not end1 it is endl
It stands for (End) (L)ine

Hope this helps
drew

##### Share on other sites
This probably doesn't really help, but you can also replace std::endl with the newline character, "\n", as in:

std::cout << "The sum of " << v1 << " and " << v2 << " is " << v1+v2 << "\n";

This is more useful when you're outputting a constant string and don't want to tack on the endl at the end, like this:

std::cout << "My birthday was five days ago!  Hooray!\n";

Just for future reference ;)

##### Share on other sites
Quote:
 Original post by silverphyre673This probably doesn't really help, but you can also replace std::endl with the newline character, "\n", as in:std::cout << "The sum of " << v1 << " and " << v2 << " is " << v1+v2 << "\n";This is more useful when you're outputting a constant string and don't want to tack on the endl at the end, like this:std::cout << "My birthday was five days ago! Hooray!\n";Just for future reference ;)

But endl flushes the buffer! :) But all kidding aside, if for whatever reason you don't want to flush the buffer right then and there, the "/n" escape character can be good for formatting text and whatnot in text-based applications, which most if not all of your early programs will be.

Example:
#include <iostream>using namespace std;int main(){    cout << "*****\n" << "*   *\n" << "* * *\n"          << "*   *\n" << "*****\n" << endl;    /* Or as one big long string if you prefer... */    cout << "*****\n*   *\n* * *\n*   *\n*****\n" << endl;    cin.get();    return 0;}

##### Share on other sites
Quote:
 But endl flushes the buffer! :) But all kidding aside, if for whatever reason you don't want to flush the buffer right then and there, the "/n" escape character can be good for formatting text and whatnot in text-based applications, which most if not all of your early programs will be.

Well, yes, but that isn't exactly a common problem :) However, if you do use newline characters like I suggested, and your text is not displaying for some reason, you can do this:

std::cout << std::flush;

To force the text to display - the above statement won't cause any additional text to be displayed.

##### Share on other sites
Ah new it was something easy like that... darn courier text..

##### Share on other sites
You know - there's a book out there where they anticipated this problem, and replaced the l with a script l in a special font, to make sure it couldn't possibly be mistaken for a 1.

And, I swear I am not making this up, we have had at least one person post here asking, basically, "How do you type that funny script l character?".

You just can't win :)

##### Share on other sites

Quote:
 Original post by ZahlmanAnd, I swear I am not making this up, we have had at least one person post here asking, basically, "How do you type that funny script l character?".

I followed a tutorial once where they used the > character to show the cursor, of so I couldn't understand how to get the code to work.

Quote:
 You just can't win :)

Source code on CD (book), or in a zip(/rar/tar.gz etc.) file (Internet tutorial)

##### Share on other sites
Or, in a perhaps more ideal situation, you could just use a font that actually has clear definition between any and all characters. I picked up on proFontWin a while ago and use it for just about everything (except for Dev-C++ because it's technically not monospaced). It was designed to be easily read at small sizes and has hashes through zeros and a clear distinction between l and 1, which most other fonts, even the san serif ones, do not.

[/continuing off topic]

Vopisk