Sign in to follow this  

Very Silly Question

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by silverphyre673
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 ;)


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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
(Since the thread is already answered I hope it's ok to go off-topic)

Quote:
Original post by Zahlman
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?".


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 this post


Link to post
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

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this