|
I am just starting with C++, and have a problem. I wrote a text game but the thing is some times I want the new question etc to start at the top of a clean black screen (that is erase all previous lines).
I could just put a pile of endl; but a couple of days ago somewhere on the site I saw a clrScrn; statment or something like that and remembered BASIC.
Could someone tell me the the #include and the correct way to use it.
Thanks in advance!
|
|
|
|
|
the DOS-command 'cls' clears the screen.
If you can execute this command...
Good luck.
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix
|
|
|
|
|
Here is you solution
If you working in Text mode
see cls() function it is defined in <conio.h>
if you working in Graphis mode
see function cleardevice() ,it is defiend in graphics.h
-----------------------------
"I Think It will Work"
Formerly Known As "Alok The Programmer" at CP
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
>>erase all previous lines).
For dos baserd compiler... the function is: clrscr();
The header file for it is #include<conio.h>
conio=Console I/O
I hope that makes you happy.
...Avenger
Remember... testing & debugging are always part of programming ...so exterminate those stinking bugs
|
|
|
|
|
im assuming you have Visual C++, unfortunatly VC++ doesnt come with the old functions like gotoxy() or clrscrn() that Dev-C++ offers
here is a ClearScreen() function i wrote along time ago (with SetXY() function)
void SetXY(int X, int Y){
COORD dwCoord;
dwCoord.X = X;
dwCoord.Y = Y;
SetConsoleCursorPosition(STDHANDLE,dwCoord);
}
void ClearScreen(){
COORD dwCoord;
DWORD nLength;
DWORD lpResult;
CONSOLE_SCREEN_BUFFER_INFO Info;
GetConsoleScreenBufferInfo(STDHANDLE, &Info);
dwCoord.X = 0;
dwCoord.Y = 0;
nLength = Info.dwSize.X * Info.dwSize.Y;
FillConsoleOutputCharacter(STDHANDLE, ' ', nLength, dwCoord, &lpResult);
SetXY(0,0);
}
ohh i almost forgot
#define STDHANDLE GetStdHandle(STD_OUTPUT_HANDLE)
|
|
|
|
|
I want to log data into MS-ACCESS from my application.
But if a machine does not have MS-ACCESS, will the application hang?
i also found that there is a microsoft access driver which is really needed instead of MS-ACESS.
Now in my application, i want to first search for the driver(instead of assuming that it is present) and then start logging. Can any1 please give me some knowledge in this matter?
|
|
|
|
|
A lot depends on the method you are using to communicate with Access?
With ADO, you should just need to redistribute MDAC.
This[^] article tells you the files need for redistributing a DAO app.
Michael
CP Blog [^]
|
|
|
|
|
i seem to be having a problem using GetFileSize in MFC
when i get the file size of anything other than an .exe it returns 0
code sample
hFile = ::CreateFile( m_FileToSplit, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
if( hFile != INVALID_HANDLE_VALUE )
{
dwFileSize = ::GetFileSize( hFile, NULL );
//doesnt seem to work
//m_FileSize.Format( "File Size: %d KB", dwFileSize );
/**/
if( dwFileSize >= 0x100000 )
{
m_FileSize.Format( "%d%s", (dwFileSize/0x100000), " MB" );
}
else if( dwFileSize >= 0x40000000 )
{
m_FileSize.Format( "%d%s", (dwFileSize/0x40000000), " GB" );
}
else
{
m_FileSize.Format( "%d%s", (dwFileSize/0x100000), " KB" );
}
/**/
CloseHandle( hFile );
}
as you may have noticed my other problem
m_FileSize.Format( "File Size: %d KB", (dwFileSize /0x100000) );
doesnt work while
m_FileSize.Format( "%d%s", (dwFileSize/0x100000), " KB" );
does anyone know why?
extra prob: m_OutputDir.Format( "%s\\%s\\Output", FileDrive, FilePath );
puts double slashes in the edit box, when i do
m_OutputDir.Format( "%s\%s\Output", FileDrive, FilePath );
it only puts single slashes, and i get a warning that \% and \O are not valid escape sequences
|
|
|
|
|
»Archer282« wrote:
//doesnt seem to work
Which means what? Is an error produced? Does the compiler complain? Does GetFileSize() return the wrong size? Does Format() not format the number correctly? Is an assertion fired, or an exception thrown?
How about:
HANDLE hFile = ::CreateFile(m_FileToSplit, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile != INVALID_HANDLE_VALUE)
{
DWORD dwFileSize = ::GetFileSize(hFile, NULL);
if (dwFileSize != INVALID_FILE_SIZE)
{
CString m_FileSize;
if (dwFileSize < 0x100000)
m_FileSize.Format("%f KB", (dwFileSize / 1024.0));
else if (dwFileSize < 0x40000000)
m_FileSize.Format("%f MB", (dwFileSize / 1048576.0));
else
m_FileSize.Format("%f GB", (dwFileSize / 1073741824.0));
}
CloseHandle(hFile);
}
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
char temp[] = "1.15";
double dbl = atof(temp);
If I run this code in Visual Studio 6 dbl = 1.15
If I run this code in Visual Studio 2003 dbl = 1.1499999999999999
Can anyone explain this for me please
|
|
|
|
|
i dont know what that would happen.
but you could alwase round it up (i think there is a round function that would suit if not you could always make your own)
|
|
|
|
|
Exactly what is telling you those values ?
I am willing to bet that if you look at the 8-byte binary value they will be identical. It is the output display that is the only thing that differs. If you use a format specifier of "%.2f" with one of the printf family of functions (print, sprintf, or fprintf) I expect that you will see 1.15.
It is important to note that it is virtually impossible to acquire exactly accurate floating point values. There are nearly always rounding errors involved that you must just deal with.
__________________________________________
a two cent stamp short of going postal.
|
|
|
|
|
Thanks for your reply
I was getting the values from the quick-watch window displayed by the debugger. The 8-byte binary value displayed in the memory window IS the same.
I have found that the real cause of my bug is the use of the pow() function from math.h.
I had code like
long rounding = 4;
double result = pow(10, -rounding);
which in vs6 returns result = 0.0001
and in vs2003 returns result = 0.0
these values ARE different in memory
Looking at math.h I think the code above was calling
long pow(long, long) resulting in 0 and auto casting the result to a double.
I changed it to
double result = pow(10.0, -rounding);
and now it works. Why its different in vs6 and vs2003 I dont know
|
|
|
|
|
As previously mentioned you should not expect an exact comparision when working with floating point numbers. To check equality you need to compare the differnce to epsilon. If the difference is < or = epsilon then the numbers are equal. Otherwise they are not.
This is done as follows: take the absolute value of the difference of the absolute values of the two floating point numbers and compare the result to epsilon. If the difference is less than or equal epsilon then the numbers are equal.
if( FLT_EPSILON =< fabsf( fabsf(f1) - fabsf(f2) ) )
printf( "numbers are equal\n" );
else
printf( "numbers are not equal\n" );
NOTE: there are double precision variants of epsilon and fabsf.
Sam
Sam
|
|
|
|
|
Hi,
My VC++ solution has 10 projects with 40 .rc files. I want to assign unique ID's to the ID's in resource.h files as there are many duplicates. So got a ResOrg.Net tool. I ran this tool which generated unique numbers for the IDs. But my application is not launching, something went wrong. I don't know what??
Can anybody help.
Also I want to allot some range ID's for all the projects.
eg. Proj 1 -> 1 - 1000
Proj 2 -> 1001 - 2000
etc....
Will there be a problem if I try alloting the ID's in this manner?
Thanks,
Prashant
|
|
|
|
|
When I have a lot of projects, I start redifining range of IDS at the bottom of the H file. All goes OK.
Jaime
|
|
|
|
|
Jaime,
The problem arises when the numerical value used by the IDS/any control is the same as some other control in another project.
At run time, the wrong string/control would be used. So for this we have to have unique ID's across all projects correct? So I am doing the cleanup, please help me out on some tools/documents available on net if any..
Thanks,
Prashant
|
|
|
|
|
I told you that I start redifining all range ID's. That way, all ID's become unique for all projects so I never have problems with that.
Since I know about that problem, I modify the ranges when I create the projects. Sorry, but I don't know any tool that does it automatically when the projects are already created.
If the application didn't launch after your modification, you only have to debug it. That's the solution to find what ID was the problem.
Jaime
|
|
|
|
|
Ok this is my source:
-----------------------------------------------------
void CTycoonDlg::OnList()
{
//Displays changes...
extern CListBox* OnList;
// Set the first visible item in the list box to be the middle item
OnList->SetTopIndex(OnList->GetCount()/2);
}
-----------------------------------------------------
I put the code inbetween it just there, and now I can't compile it...
OnList is a list box, and when I try to compile it I get this error...
--------------------Configuration: Tycoon - Win32 Debug--------------------
Compiling...
TycoonDlg.cpp
Linking...
TycoonDlg.obj : error LNK2001: unresolved external symbol "class CListBox * OnList" (?OnList@@3PAVCListBox@@A)
Debug/Tycoon.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
Tycoon.exe - 2 error(s), 0 warning(s)
Any Ideas?
I'm not that good at debugging errors.
Anyways, please keep it simple, I don't really understand much to MFC, im new to it.
I know a bit to C++.
|
|
|
|
|
extern CListBox* OnList tells the compiler "there's a variable called OnList with type CListBox* that is declared in some other source file". Have you declared OnList in some other file? If not, it should probably be a local variable and you need to initialize the pointer before using it.
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
You cannot stop me with paramecium alone!
|
|
|
|
|
Hello,
I am using of
CDaoDatabase CDaoRecordset Classes and I want to know that How can I use SQL Commands by them?
Like this(I want to have filter)
"select * from Name where name='something'"
and How can I Set a Field to an Edit Object?
Best Wishes,
Thanks.
|
|
|
|
|
the follwing piece of code might help you...
CDaodatabase database;
database.Create("C:\sample_log.mdb");
CString SqlCmd = "CREATE TABLE list (NAME VARCHAR(20), AGE INT, DATE VARCHAR(20), TIME VARCHAR(20));";
database.Execute(SqlCmd);
database.Close();
now to search....
build a query string and execute it...
CString query = "Select * from list where NAME='ABCD'"
CDaoDatabase db;
db.Open("C:\sample_log.mdb");
CDaoRecordSet record(&db);
record.Open(AFX_DAO_USE_DEFAULT_TYPE,query,0);
Then...
while(!recor.IsEOF())
{
.....
use GetFieldValue() for each record in the recordset
}
record.Close();
db.Close();
|
|
|
|
|
hi i want to be able to create folders programaticly
also i want to be able to delete files programiticly
i also need to be able to access a folder and loop through each file in the folder
can someone give me some tips or show me where to look
Thanks
|
|
|
|
|
|
how did you get the text and underline to be differnt colors !
Bikram Singh
|
|
|
|