can we insert symbols ? ? dev c++

Pages: 12
and UTF-8 isn't a code page, it is an encoding system.


Whether or not that's technically true is a matter of semantics. My point is it's one of the code pages you can select from through WinAPI, and therefore behaves as if it were a code page.

MS's code pages were a good answer to the existing technology problems.


No argument here.

Unicode and UTF require existing technology to change to match them.


Not really. MS does a good job of supporting both systems. Flip a few switches and you can work in either system.

I'm not saying they should completely the code page system. I'm saying they should change the default behavior for programs where the desired code page isn't explicitly chosen. UTF-8 really should be the default. It's the modern accepted standard worldwide.

Worried about breaking old programs where the code page was never explicitly set? Then only implement it in new programs. Easily accomplished by having the compiler embed some "hidden" code to switch the code page before main() is executed.

Worried that will hinder portability? Make it a compiler switch that can be turned off.

There are lots of things they could be doing to fix this -- they're just not doing any of them. IMO it's a mistake. And it could easily be corrected.
mrfaosfx wrote:
Disch, I always wondered that myself, its one of those half-assed jobs M$ does, they make an implementation and leave the rest some where else.
You've missed the point. M$ didn't do a half-assed job. They did a double-assed job, supporting two systems, which is more than a lot of developers do.

Disch wrote:
Whether or not that's technically true is a matter of semantics
No, it is not. They are orthogonal things.

I agree with you, though, that the Windows Console program has some significant flaws. But it does have to accomodate a lot of backwards compatability, and so, barring some magic switch like you indicate, it cannot improve much.
sorry i dont understand it well.
Last edited on
Duaos wrote:
No, it is not. They are orthogonal things.


My point is that UTF-8 is implemented as a code page in WinAPI. You can select it like any other code page. Therefore from the developer's standpoint, it might as well be just another code page, even if it technically isn't the exact same thing.

As you can see from the site, UTF-8 (bottom of the list) is listed among all the other available code pages, even if it technically isn't the same thing:
http://msdn.microsoft.com/en-us/library/dd317756(v=VS.85).aspx

Also there's a note at the top of the page recommending you use a UTF encoding scheme for the most consistent results, so on some level, MS (or at least the guy that wrote that webpage) even agrees with me that it should be the default -- or at the very least the most favored.

But it does have to accomodate a lot of backwards compatability, and so, barring some magic switch like you indicate, it cannot improve much.


I understand where you're coming from. I can certainly agree that maintaining backwards compatibiliy is difficult and extremely important.

But MS has a great advantage of having their own compiler that is in widespread use. All it takes is to change the default settings in the compiler to compile new programs with UTF-8 as the default output scheme. Nothing in the API has to change, and therefore no backwards compatibility has to be sacrificed. I don't see what's so magical about that. It seems like a very simple and pragmatic solution.
@Black cpp
Please read the thread before posting drivel unrelated answers.

@Disch
I like that solution.

(BTW, I am familiar with that page and link. That stuff exists mostly for translation between character sets, and doesn't work properly in all places that a code page should apply.)
Last edited on

Duoas (4599) Dec 30, 2010 at 5:53am
Also, just because you can put the symbol in your text file -- it may not save correctly.

To print the square root symbol to the Windows console using the default code page, use:

1
2
3
4
5
6
7
8
#include <iostream>
using namespace std;

int main()
{
cout << "\xFB" << "9 = 3\n";
return 0;
}

Hope this helps.


wow gr8 man ..thanks for ur help ..it worked .well could u tell me from where i can learn to use unicodes like this symbol u used "\xFB"
The symbol I used is not Unicode. It is in the default Windows Console code page "Extended ASCII Set". Hence my statement that it is for use on the Windows Console, since that is the only place it will display properly.

To find them, check out http://www.asciitable.com/

If you write your program in Windows and send it to your professor (who may be using Unix or Linux), it will not work for him.


For modern Linuxes, you will want to actually use Unicode by way of UTF-8. You can google into Wikipedia's unicode listings to get pages like http://en.wikipedia.org/wiki/Mathematical_operators_and_symbols_in_Unicode, which show that the square root symbol to be U+221A. You'll have to convert that to a UTF-8 sequence to print it.

A simplistic way to convert to UTF-8 is to use the Windows Notepad editor. Copy and paste the single character you want into the file and save it as UTF-8. Use the following program to get something you can paste into your program:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <algorithm>
#include <fstream>
#include <iostream>
#include <iterator>
using namespace std;

int usage( const char* program_name, int exit_code )
  {
  cout << "Notepad UTF-8 character file to C++ string converter.\n"
          "To use, type:\n\n"

          "  " << program_name << " FILENAME\n\n"

          "at the command prompt, where FILENAME is the name of the Notepad file.\n";

  return exit_code;
  }

void display( char c )
  {
  cout << "\\x" << ((int)c & 0xFF);
  }

int main( int argc, char** argv )
  {
  if (argc != 2) return usage( argv[ 0 ], 0 );
  ifstream f( argv[ 1 ], ios::binary );
  if (!f) return usage( argv[ 0 ], 1 );

  f >> noskipws;
  istream_iterator <char> fin( f );
  advance( fin, 3 );  // skip the stupid Windows UTF-8 BOM

  cout << "\"" << uppercase << hex;
  for_each( fin, istream_iterator <char> (), display );
  cout << "\"\n";

  return 0;
  }

Running the program gets me the string "\xE2\x88\x9A", which is the UTF-8 sequence to print U+221A on your Linux console.


Finally, use a simple #define to tell the systems apart:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
using namespace std;

#ifdef _WIN32
  const char sqrt_symbol[] = "\xFB";
#else
  const char sqrt_symbol[] = "\xE2\x88\x9A";
#endif

int main()
  {
  cout << sqrt_symbol << "9 = 3\n";
  return 0;
  }

Your professor will be OK with that.
ok thanks a lot .
Topic archived. No new replies allowed.
Pages: 12