| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Re: Organizing source code |
From: Gregg N
Geo wrote:
> Fun little routine you have there.. Ok so it works great with characters but
> here is what I tried:
>
> int geo=0;
> do
> {
> ::WriteConsoleOutputCharacter ( hC,
> geo,
> 10,
> c,
> &dw ) ;
> geo++
> }
> while (geo < 50000);
>
> and it didn't like the fact that geo is an int, so what part of
> WriteConsoleOutputCharacter specifies that it's char instead of int, is that
> the c, part or is it a totally different function I need to find?
C++ is a strongly-typed language. You can't use an int where a string is expected.
If you look up this function in MSDN, you will see that the type of the
second parameter must be pointer to array of characters not int. To write
the int you have to first get its text representation. One way to do this
is to use the standard c++ stringstream class, which allows you to use a
string buffer the way you would use std:cout. At the beginning, include the
sstream header:
#include
Within your loop, format the string like this:
std::ostringstream oss;
oss << geo;
std::string str = oss.str();
::WriteConsoleOutputCharacter ( hC,
str.c_str(),
str.size(),
c,
&dw ) ;
Note that the ostringstream takes care of allocating the proper amount of
memory for the string. The str() member function of ostringstream returns a
copy of its internal string after formatting. The c_str() member function
of string extracts a C-style string (an array of characters) from a C++
string.
Another way to do this is to use the formatting function that is part of
the Windows API rather than the facilities in the C++ library, but I don't
remember offhand what its name is. I think it has additional capabilities
having to do with language localization.
Gregg
--- BBBS/NT v4.01 Flag-5
* Origin: Barktopia BBS Site http://HarborWebs.com:8081 (1:379/45)SEEN-BY: 633/267 270 5030/786 @PATH: 379/45 1 396/45 106/2000 633/267 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.