Groups | Search | Server Info | Login | Register


Groups > alt.comp.lang.c++.misc > #11

Re: ASCII Codes

Path csiph.com!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From Ben Bacarisse <ben@bsb.me.uk>
Newsgroups comp.lang.c++, alt.comp.lang.c++.misc, free.test
Subject Re: ASCII Codes
Date Mon, 09 Sep 2024 13:44:40 +0100
Organization A noiseless patient Spider
Lines 66
Message-ID <87jzflknd3.fsf@bsb.me.uk> (permalink)
References <Q%nDO.343686$8jx2.215799@fx17.iad>
MIME-Version 1.0
Content-Type text/plain
Injection-Date Mon, 09 Sep 2024 14:44:49 +0200 (CEST)
Injection-Info dont-email.me; posting-host="648ca36dd03115d68b88b1c518c413d0"; logging-data="2529803"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19t23BF+iiApgKGBMig8RDRteSchU4Cvk4="
User-Agent Gnus/5.13 (Gnus v5.13)
Cancel-Lock sha1:oEjFFJyIA+o/dPfAtqZNFCw6EPM= sha1:o/c7DzCBfc2W2eaLMaWa/0tU5R0=
X-BSB-Auth 1.6df6ab889f6b3631ce05.20240909134440BST.87jzflknd3.fsf@bsb.me.uk
Xref csiph.com comp.lang.c++:120003 alt.comp.lang.c++.misc:11 free.test:1373

Cross-posted to 3 groups.

Show key headers only | View raw


Student Project <student@invalid.invalid> writes:

> This one works as expected but there is definitely a room for 
> improvement. :-)
>
> #include <iostream>
> #include <vector>
>
> using namespace std;

Students tend to do this because it save a little typing, but it's
generally considered a bad idea in anything but the shortest programs.

> int main()
> {
>     system("color 0A");
>     system("cls");
>     vector<string> obj = {
>         "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
>         "exclamation mark",
>         "quotation mark",
>         "number sign",
...
>         "digit 0",
...
>         "digit 9",
>         "colon",
...
>         "at sign",
>         "uppercase A",
...
>         "uppercase Z",
...
>         "grave accent",
>         "lowercase a",
...
>         "lowercase z",
>         "left curly brace",
>         "vertical bar",
>         "right curly brace",
>         "tilde" };

One thing that would help a lot would be to stop relying on getting the
order exactly right.  You could, at the expense of more typing, use
assignments:

  obj['!'] = "exclamation mark";

This would make any errors obvious.

And then, if you wanted to try something a little more sophisticated,
you could use a loop for the digits and the letters.

>
>     cout << "\tCode" << "\tCharacter" << "\tWhat it means" << "\n";
>     cout << "\t#####################################\n\n";
>     for (int i = 33; i <= 126; i++)
>     {
>         cout << "\t" << i << "\t" << (char)i << "\t\t" << obj[i] << "\n";
>     }
>
>     return 0;
> }

-- 
Ben.

Back to alt.comp.lang.c++.misc | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

ASCII Codes Student Project <student@invalid.invalid> - 2024-09-08 20:45 +0000
  Re: ASCII Codes Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-09-08 14:32 -0700
    Re: ASCII Codes "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-09-08 14:37 -0700
      Re: ASCII Codes "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-09-08 14:39 -0700
    Re: ASCII Codes Chris Ahlstrom <OFeem1987@teleworm.us> - 2024-09-09 09:41 -0400
    Re: ASCII Codes red floyd <no.spam.here@its.invalid> - 2024-09-09 21:44 -0700
  Re: ASCII Codes Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-09 14:32 +0200
  Re: ASCII Codes Ben Bacarisse <ben@bsb.me.uk> - 2024-09-09 13:44 +0100
    Re: ASCII Codes Chris Ahlstrom <OFeem1987@teleworm.us> - 2024-09-09 09:43 -0400
    Re: ASCII Codes Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-09 18:52 +0200
      Re: ASCII Codes Student Project <student@invalid.invalid> - 2024-09-10 01:04 +0100
        Re: ASCII Codes Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-10 10:32 +0200
  Re: ASCII Codes Paavo Helde <eesnimi@osa.pri.ee> - 2024-09-10 07:55 +0300

csiph-web