-1

I don't know the cause of errors compiling using g ++. Am I using obsolete classes?

My MWE:

#include <iostream>
using namespace std;
int main()
{
system("cls");
cout << "\n\n";
cout <<"\n\t\xDC\xDC\xDB\xDB\xDB\xDB\xDC\xDC";
cout <<"\n\t\xDF0\xDF\xDF\xDF\xDF0\xDF";
cout <<"\n\n";
cout <<"\n\t\xDC\xDC\xDB\xDB\xDB\xDB\xDB\xDB\xDB";
cout <<"\n\t\xDF0\xDF\xDF\xDF\xDF\xDF00\xDF";
cout << "\n\n";
cout << endl;
system("PAUSE");
return 0;
}

**

Result at compiling:

$ g++ 14.cpp
14.cpp: In function ‘int main()’:
14.cpp:11:9: warning: hex escape sequence out of range
11 | cout <<"\n\t\xDF0\xDF\xDF\xDF\xDF0\xDF";
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
14.cpp:11:9: warning: hex escape sequence out of range
14.cpp:16:9: warning: hex escape sequence out of range
16 | cout <<"\n\t\xDF0\xDF\xDF\xDF\xDF\xDF00\xDF";
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
14.cpp:16:9: warning: hex escape sequence out of range 
$ ./a.out
sh: cls: command not found
7beggars_nnnnm
  • 697
  • 3
  • 12

1 Answers1

2

A hex escape sequence supposed to be formatted as \Xnn. It complains because you provide more than 2 hex values as in \xDF0 and \xDF00.

---EDIT---

For completeness, quote from cppreference:

Hexadecimal escape sequences have no length limit and terminate at the first character that is not a valid hexadecimal digit. If the value represented by a single hexadecimal escape sequence does not fit the range of values represented by the character type used in this string literal (char, char16_t, char32_t, or wchar_t), the result is unspecified.

And to stop escaping hex characters, another quote from cppreference:

If a valid hex digit follows a hex escape in a string literal, it would fail to compile as an invalid escape sequence. String concatenation can be used as a workaround:

//const char* p = "\xfff"; // error: hex escape sequence out of range
const char* p = "\xff""f"; // OK: the literal is const char[3] holding {'\xff','f','\0'}
seleciii44
  • 1,529
  • 3
  • 13
  • 26
  • 1
    I am learning to program in C ++ and this example was presented in the book I am reading for it. I will endeavor to try to correct by following your guidance and so may mark it as resolved if this is the solution. Grateful for your attention. – 7beggars_nnnnm Jul 29 '19 at 21:49