Very Silly Question
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?
This probably doesn't really help, but you can also replace std::endl with the newline character, "\n", as in:
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:
Just for future reference ;)
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 ;)
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;}
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.
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 :)
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 :)
(Since the thread is already answered I hope it's ok to go off-topic)
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.
Source code on CD (book), or in a zip(/rar/tar.gz etc.) file (Internet tutorial)
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)
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
[/continuing off topic]
Vopisk
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement