Sign in to follow this  

C++: Multi-string literals are deprecated?

This topic is 4355 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'm getting this error when I try to compile one of the example codes in my C++ book. What does it mean? I'm typing the code exactly like it is in the book. I'm using "Bloodshed Dev-C++" Also... it's trying to teach me about hex and octal values, is there any reason why I would use these instead of normal numbers?

Share this post


Link to post
Share on other sites
// hexoct.cpp -- shows hex and octal constants
#include <iostream>
using namespace std;
int main()
{
int chest = 42; // decimal integer constant
int waist = 0x42; // hexadecimal integer constant
int inseam = 042; // octal integer constant

cout << "Monsieur cuts a striking figure!\n";
cout << "chest = " << chest << "\n";
cout << "waist = " << waist << "\n";
cout << "inseam = " << inseam << "\n";
return 0;
}

Odd thing was... I just tried to compile it on this computer, and I didn't get any errors at all...

I'm really new at this -_-

Share this post


Link to post
Share on other sites
The error in question means you can't have a line break in the middle of a string, like so:
cout << "this is some
multi line string" << endl;

That you're seeing it probably means you missed a closing quotation mark somewhere.

Share this post


Link to post
Share on other sites
"deprecated" means obsolete but still supported. The compiler is letting you know that while this code will compile today it might not in the future. You can disable this sort of warning with a #pragma in most compilers.

As for the numbers, I have never in all my years programming seen an octal number anywhere other than a textbook. Hex numbers you see from time to time. The only one I've ever typed into code myself is 0xFFFFFFFF. You outta be able to read them well enough to know why someone might want 0xFFFFFFFF but apart from that, eh. The little "calc" program that comes with windows will do conversion for you, btw.

Share this post


Link to post
Share on other sites
Quote:
Original post by Xantan the Foul
Also... it's trying to teach me about hex and octal values, is there any reason why I would use these instead of normal numbers?

Since there are no binary literals, if you want to hardcode binary into your application, it's much easier to do so in hex, since an n-hexit hex number can be digit-by-digit expanted to a 4n-bit binary number.

0xAC is 1010 1100, for example, since 0xA is 1010(base2) and 0xB is 1100(base2)
Compare to 172, which is much harder to mentally convert to 10101100
Octal is also easy, since an octal octit expands to 3 bits: 01101100(base2) is 0254 (octal)

Share this post


Link to post
Share on other sites

This topic is 4355 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