|
There are probably lots of ways to do this - but one that springs to (my) mind is "Custom Draw". See here. Doing a search for "Custom Draw" on the The Code Project and Google will no doubt give many hits.
Steve
|
|
|
|
|
Hi all,
Yesterday I bought Robert Lafore's Object Oriented Programming in C++ book but there is a problem I really can't solve.
When I want to write the example codes in the book, I click File menu > New > File and then select Visual C++ > C++ File (.cpp). And I get a new window to code things. But the problem is whenever I press Build from the Build menu, I get this error:
C:\OOP\NewX\NewX.cpp(9): fatal error C1010: unexpected end of file while looking for precompiled header directive
Is Build what I should use to see the result of the code?
What I have written was this:
#include <iostream>
using namespace std;
int main()
{
cout << “Every age has a language of its own\n”;
return 0;
}
and then this:
cout << “Every age has a language of its own\n”
Please help me to solve this problem as this is the key thing to learn C++.
Btw I have Visual C++ 2005 Express Edition.
Thanks in advance,
Joshua
|
|
|
|
|
if its just for a (excuse me, not meaning to demean you in any way) 'trivial' program you're playing around with, then in MSVC 6 I would have gone
Project -> Settings
Selected the source .cpp file
Gone 'to the right' pane and selected 'C++', Category 'Precompiled Headers', and ticked 'Not using precompiled headers'
In real world programs, this can mean that stdafx.h isnt being used correctly, but if you're working on small example, I'd ignore MSVC technicalities in favour of getting something to build and run (else it gets way boring) ...
'Precompiled Headers' can also be set at a project level, but I'm not au-fait with the .NET Editor/Environment, so I'll have to leave that with you - 'either one' should do the trick
'g'
-- modified at 22:08 Friday 20th January, 2006
|
|
|
|
|
Thanks alot Garth. Actually I am trying to learn c++, so this is really important but this kind of behaviour really confused me. I have now turned off precompiled headers and got these errors:
c:\documents and settings\joshua\my documents\visual studio 2005\projects\new\new\new.cpp(6) : error C2065: '“Every' : undeclared identifier
c:\documents and settings\joshua\my documents\visual studio 2005\projects\new\new\new.cpp(6) : error C2146: syntax error : missing ';' before identifier 'age'
c:\documents and settings\joshua\my documents\visual studio 2005\projects\new\new\new.cpp(6) : error C2065: 'age' : undeclared identifier
c:\documents and settings\joshua\my documents\visual studio 2005\projects\new\new\new.cpp(6) : error C2146: syntax error : missing ';' before identifier 'has'
c:\documents and settings\joshua\my documents\visual studio 2005\projects\new\new\new.cpp(6) : error C2065: 'has' : undeclared identifier
c:\documents and settings\joshua\my documents\visual studio 2005\projects\new\new\new.cpp(6) : error C2146: syntax error : missing ';' before identifier 'a'
c:\documents and settings\joshua\my documents\visual studio 2005\projects\new\new\new.cpp(6) : error C2065: 'a' : undeclared identifier
c:\documents and settings\joshua\my documents\visual studio 2005\projects\new\new\new.cpp(6) : error C2146: syntax error : missing ';' before identifier 'language'
c:\documents and settings\joshua\my documents\visual studio 2005\projects\new\new\new.cpp(6) : error C2065: 'language' : undeclared identifier
c:\documents and settings\joshua\my documents\visual studio 2005\projects\new\new\new.cpp(6) : error C2146: syntax error : missing ';' before identifier 'of'
c:\documents and settings\joshua\my documents\visual studio 2005\projects\new\new\new.cpp(6) : error C2065: 'of' : undeclared identifier
c:\documents and settings\joshua\my documents\visual studio 2005\projects\new\new\new.cpp(6) : error C2146: syntax error : missing ';' before identifier 'its'
c:\documents and settings\joshua\my documents\visual studio 2005\projects\new\new\new.cpp(6) : error C2017: illegal escape sequence
c:\documents and settings\joshua\my documents\visual studio 2005\projects\new\new\new.cpp(6) : error C2065: 'its' : undeclared identifier
c:\documents and settings\joshua\my documents\visual studio 2005\projects\new\new\new.cpp(6) : error C2146: syntax error : missing ';' before identifier 'own'
c:\documents and settings\joshua\my documents\visual studio 2005\projects\new\new\new.cpp(6) : error C2065: 'own' : undeclared identifier
c:\documents and settings\joshua\my documents\visual studio 2005\projects\new\new\new.cpp(6) : error C2146: syntax error : missing ';' before identifier 'n”'
c:\documents and settings\joshua\my documents\visual studio 2005\projects\new\new\new.cpp(6) : error C2065: 'n”' : undeclared identifier
|
|
|
|
|
ok, its a list of errors - it looks like you've stuffed the definition of a character string of some sort .. [deleted] .. sorry, I thought you hadnt posted the code .. looking back you did
I'll try to look at it in a mo
'g'
-- modified at 5:35 Saturday 21st January, 2006
|
|
|
|
|
still not exactely sure how your project is set up (did you use a wizard ?), but if I have
#include "stdafx.h"
#include <iostream>
int main(int argc, char* argv[])
{
std::cout << "now is the time\n" ;
return 0;
}
I dont have any issues ..
If you're not generating your project using a wizard, it can get very hard getting all the settings right, so start by creating your projects with the 'wizard'...
so try this
shut down VS .NET, then start it up to get a clean slate
select file, new, projects, Win32 Console Application
set a location, give the project a name eg test1
instruct the wizard to create a "Simple Application"
Then select the fileview tab, source file, test1.cpp
edit test1.cpp to look like mine, build it (F7), it should compile cleanly, then CTRL+F5 to run it ..
I often think its hard on win32 to learn this, because you have a complicated IDE to master as well - I learnt on Unix and to some extend, it was easier
see how you go with that ..
note the std:: in front of the cout - its because within iostream library, its exporting the 'cout' into what's known as a 'namespace' - so to reference it, you need the std:: (there is another way around this, lets walk before we can run)
'g'
|
|
|
|
|
Hey Garth,
You simply rock! It works now. I can't believe I saw it working man.
If you don't mind can I ask why I have to build and then use execute? In the language I know, I only use evaulate all and then it compiles and works.
Is there a reason for this?
Thanks again!!!
|
|
|
|
|
'build' in your IDE is a compile of the source code into an object module, and then link the required object modules into an executable program (program in this case as opposed to dll etc) .. this executable program can be run directly by the host platform ie Win32 (thats a big simplification)
'execute' actually calls/runs the .exe and shows its output (if you look, in likely to be a 'debug' folder under where you created the test1 project, you'll have test1.exe, plus some other objects) .. you could run a cmd prompt, change to the directory where the .exe is (or copy it somewhere useful) and simply run it from the command line
Joshua N wrote: In the language I know
ok .. its probably a 'bytecode'/interpreted language, like java perhaps ? .. in this case, the source code is compiled into an intermediate representation, 'bytecode', that is then interpreted code by code/instruction by instruction by an engine - a 'java virtual machine "jvm"' - ie, the JVM calls the underlying os functions etc and performs the functionality (again, simplistic for this response)
ok, so, you're started .. at some stage, I suggest you experiment with doing the 'build' stage, then instead of running a program using CTRL+F5, use 'debug' options (there's a menu for them, showing some of the keys I'll mention below) .. for example, pressing F10 after a 'clean' build will run the program one statement at a time (so you'll have to press it more than once), and you can see the contents of your variables etc in a window on the screen. You can 'step into' functions, using F11, you can put the cursor on a line of code and say 'run to here', you can set a stop called a breakpoint on a line and push F5 to run to that breakpoint (put cursor on line, select 'hand symbol' and a red dot should appear next to the line), and of course you can have more than one breakpoint ... knowing how to use these options will save you many hours of grief when it comes to debugging something more complex .. it will take some time to learn it and find the various windows etc, but dont most things worthwhile take some effort to learn ?
'g'
-- modified at 18:19 Saturday 21st January, 2006
|
|
|
|
|
First of all, you placed your last cout out of main() and you forgot the ; at the end of the statement.
|
|
|
|
|
Sorry Radio,
I did this to show that I even can't run a sinle line. Do I need to use; after every line btw?
Thanks!
|
|
|
|
|
Hi Joshua,
There are some instances where we don't need to use ";" like in macros and comments.
Before you start c++, make sure to orient yourself with the basics of the subject first (the syntax, how to use the IDE, the capabilities of C++) for you to at least have an idea what's in store for you ahead. There are lots of C++ tutorials online, just to guide you along the way.
=waxie=
|
|
|
|
|
I think you are missing a #include file name, and possibly you're using those strange slanty quotes. You need to do something like this:
#include <iostream>
using namespace std;
int main()
{
cout << "Every age has a language of its own\n";
return 0;
}
|
|
|
|
|
Hello,
Is there a way to make a connection to an access database using the .NET framework? So I'm looking for functionality like what is in System.Data.SqlClient, but I'd like to connect to an access database.
Also, when you pass a "connection string" to a SqlConnection object, you need to include a database name.. Does that name refer to an ODBC connection or just to the name of the database in SQL server?
Thank you,
-Jordan
|
|
|
|
|
Check out this article.[^]
ed
~"Watch your thoughts; they become your words. Watch your words they become your actions.
Watch your actions; they become your habits. Watch your habits; they become your character.
Watch your character; it becomes your destiny."
-Frank Outlaw.
|
|
|
|
|
Thanks Ed. It looks like I need to use an OleDbConnection.
--Jordan
|
|
|
|
|
Hey all, I have the Visual Studio Express Beta 2 with Team System in there including the code coverage and testing stuff. Does anyone know of a tutorial I can check out on how to use the code coverage?
When I did try to use the "New Test" menu item, it auto generated a bunch of code that looked like C#. I tried to add in my own C++ stuff but the compile failed terribly with over 8000 (yes that's right 8 thousand) errors (and it was still going when I canceled it). Perhaps you can only use the code coverage for C# code and not C++?
Thanks
azbok
|
|
|
|
|
Hi folks,
I'm creating a simple Visual C++ program which is supposed to display an animation: A timer event
calls a panel_Paint() which writes the graphics on screen.
My problem is that I cannot store data anywhere that will tell the panel_Paint() function
at which frame of the animation it is so it knows which file to display -
if I initialize a variable inside the function, it will be re-initialized next time it is
called, and if I try to initialize a variable outside the function, I am told that I can only initialize static variables there.
I'm new to Visual C++ and this kind of event-driven programming, maybe somebody can tell me
where I can store data for my functions to use. Thanks in advance.
-- modified at 20:59 Friday 20th January, 2006
|
|
|
|
|
I need more information about the structure of your program to answer this question - But normally the data would be stored in a member variable of the class that contains the callback function.
Steve
|
|
|
|
|
I have a plain Form class in which I have a function "timer1_Tick" which is executed on each tick event. In this function I use this line in order to call up a panel1_Paint function, which is also part of the Form class:
[code]
panel1->Paint += gcnew System::Windows::Forms::PaintEventHandler( this, &Form1::panel1_Paint );[/code]
And that's it. I just need a place where to initialize data. Obviously I can't initialize the data inside my timer1_Tick or inside the panel1_Paint function because it'd be initialized again and again.
I tried initializing some values in the constructor Form1():
[code]
int a;
Bitmap^ bitmap;
Form1() {
InitializeComponent();
int a = 20;
Bitmap^ bitmap = gcnew Bitmap("test.gif");
}
[/code]
But when I try to use them in my panel1_Paint function further down I see that they, while they have been initialized, they have not been assigned values yet. This is a variable scope problem I guess.
|
|
|
|
|
I would think that if you declare the variable as static it will retain it's value between invocations of the function. It would still retain function scope.
void funct (int sumpin, char *stuff)
{
static int var = 0;
[other code]
}
Lilith
|
|
|
|
|
Yes, but I need non-static variables..
I've solved the problem anyway -- I initialized the variable
twice, inside and outside of the function - so two instances of the variable, one with class scope and one with function scope were created. Yea, newbie mistake, so embarrassing
Still, thanks a lot guys for the quick help.
|
|
|
|
|
I don't understand exactly what you're getting at - But based on my understanding (possibly flawed) here's what I'd do:
<code>class CMyClass
{
public:
CMyClass()
{
m_SomeVariable = 3;
}
void SomeFunction()
{
}
private:
int m_SomeVariable;
}</code><pre>
Steve
|
|
|
|
|
This raises a question for the assembled experts here. Under most circumstances a variable declared as static in a function retains its last value on re-entry to the function. I can understand if an object is destroyed and re-created that the variable resets. Variables declared as static in a class are available (common) to all objects of the class. Static class methods don't receive the 'this' pointer to the object.
Now, what about static variables inside class methods? Do they still retain their value on exit upon re-entry? Or is there something about the way classes act that changes this behavior?
Lilith
|
|
|
|
|
Static variables inside functions, be they global, member or static member functions, are initialised on first use and retain the value between invocations. If the class that contains the member with a static local variable is destroyed and re-created the variable still retains its value - It does not reset.
Steve
|
|
|
|
|
Folks,
First post here - sorry if wrong forum or has been asked before.
I'm looking for an API call or "a strategy" to allow my program to
determine if it is being run during a normal interactive Windows logon
process (for example, as part of a logon script) versus afterward.
This program will only be run on W2K and above. Been looking at the
LSA functions, not seeing anything obvious.
Thinking about things like enumerating processes and like, looking for
some kinda context.
Anyone see anything about doing this kinda thing, on this board or
elsewhere.
-Shawn
|
|
|
|
|