I wanted to know if there is a way to add the "^2" character in a CString. I am trying to add it so I can display inches squared. Or must I define a small font and use that?
^2 Character in CStrings?
Page 1 of 17 Replies - 896 Views - Last Post: 01 February 2012 - 04:09 PM
Replies To: ^2 Character in CStrings?
#2
Re: ^2 Character in CStrings?
Posted 01 February 2012 - 07:08 AM
Do you mean a superscripted 2?
12452
12452
#3
Re: ^2 Character in CStrings?
Posted 01 February 2012 - 07:31 AM
Yeah, that is what I was trying to say. I couldnt think of superscripted.
#4
Re: ^2 Character in CStrings?
Posted 01 February 2012 - 07:36 AM
Sometimes just knowing the terms is half the battle.
Googling for "C++ superscript" got me lots of examples including this one.
http://stackoverflow...-console-output
Googling for "C++ superscript" got me lots of examples including this one.
http://stackoverflow...-console-output
#5
Re: ^2 Character in CStrings?
Posted 01 February 2012 - 07:51 AM
I cannot embed it in Microsoft Visual 2008. I am trying to do char(0xB2) but to no avail.
#6
Re: ^2 Character in CStrings?
Posted 01 February 2012 - 08:22 AM
Let's see your code trying to do it
#7
Re: ^2 Character in CStrings?
Posted 01 February 2012 - 09:18 AM
Just FYI, you can't do this in standard C++ and I'm not even sure this can be done in the console. Something like this would generally require a graphic interface.
#8
Re: ^2 Character in CStrings?
Posted 01 February 2012 - 04:09 PM
Basically it CAN be done if the console is configured properly to do so. However expanding past simple ASCII in the console can be tricky and is an area of much debate because what works on one computer (with its particular configuration) may or may-not work on the next. So you have "experts" giving advice on how to do it "properly" and invariable there is someone complaining that it didn't work for them.
So if you are writing an application that others will use and needs to support a wide variety of user configurations... try as you might you will never please everyone and your best bet is to work with wide-characters and hope for the best - deal with the bug reports as they come in.
If the program is just for your use or for an assignment you can just try to figure out what works for your computer and for your instructor's computer.
The Following code should work on many systems:
Here the extended ASCII char 253 (0xFD) is output. On some systems this works, on others it does not.
on other systems the above will work by outputting wide chars.
On windows you would probably want to ensure that you had the right encoding for the console's current code page:
The code page that my console seems to be using on my desktop is IBM437 (which is basically the extended ASCII character set).
You can test other "code pages" by using the command: cpch in the console:
C:> cpch 65001 -- sets the "code page" to UTF8 - which is actually a multi-byte encoding not a code page thus the quotes.
If your want you can set the code page from your code using SetConsoleOutputCP(int).
So if you are writing an application that others will use and needs to support a wide variety of user configurations... try as you might you will never please everyone and your best bet is to work with wide-characters and hope for the best - deal with the bug reports as they come in.
If the program is just for your use or for an assignment you can just try to figure out what works for your computer and for your instructor's computer.
The Following code should work on many systems:
#include <iostream>
using namespace std;
int main() {
cout << "E = mC" << char(253) << endl;
return 0;
}
Here the extended ASCII char 253 (0xFD) is output. On some systems this works, on others it does not.
#include <iostream>
using namespace std;
int main() {
wcout << L"E = mC˛" << endl;
return 0;
}
or#include <iostream>
using namespace std;
int main() {
const wchar_t super2 = 0x00B2;
wcout << L"E = mC" << super2 << endl;
return 0;
}
on other systems the above will work by outputting wide chars.
On windows you would probably want to ensure that you had the right encoding for the console's current code page:
#define UNICODE
#include <windows.h>
#include <iostream>
using namespace std;
int main() {
wchar_t str[] = L"E = mC˛";
//we need a handle to the stdout
HANDLE stdoutHandle = GetStdHandle(STD_OUTPUT_HANDLE);
int consolCP = GetConsoleOutputCP();
wcout << L"Console Code Page: " << consolCP << endl;
int charCount = WideCharToMultiByte(consolCP, 0, str, -1, 0, 0, 0, 0);
//temporary place for our MultiByte char...
char* tempMBString = new char[charCount];
WideCharToMultiByte( consolCP, 0, str, -1, tempMBString, charCount, 0, 0);
DWORD numBytesWritten;
WriteFile(stdoutHandle, tempMBString, charCount-1, &numBytesWritten, 0);
delete[] tempMBString;
return 0;
}
The code page that my console seems to be using on my desktop is IBM437 (which is basically the extended ASCII character set).
You can test other "code pages" by using the command: cpch in the console:
C:> cpch 65001 -- sets the "code page" to UTF8 - which is actually a multi-byte encoding not a code page thus the quotes.
If your want you can set the code page from your code using SetConsoleOutputCP(int).
Page 1 of 1

New Topic/Question
Reply


MultiQuote








|