|
If you're using managed C++, then yes, the StreamWriter is what you want. However, I'd recommend using ofstream instead/.
#include <fstream>
using std::ofstream;
ofstream str(filePath);
str << ID << ", " << age << ", "
etc.
Now, if these things are stored in a struct, you could look at my <a href="http://www.codeproject.com/vcpp/stl/iostreaminserters.asp" rel="nofollow">article</a>[<a href="http://www.codeproject.com/vcpp/stl/iostreaminserters.asp" target="_blank" rel="nofollow" title="New Window">^</a>] on how to stream custom types, then you could do it all in one line and code the commans into the inserter.
Christian Graus - Microsoft MVP - C++
-- modified at 17:00 Tuesday 15th November, 2005
|
|
|
|
|
Thanks so much for this.
I've got that all working so its very much appreciated.
Thanks
Georgie
|
|
|
|
|
There is a thread in windows form application.
I start several instances of this thread, and within its code it opens and closes from time to time a file on disk.
How to organize exclusive access to this file from several instances of a thread.
Thread:
...
...
open the same file //need to wait while this file is opened in
read data from it //another instance of this thread
write data to it
close file
...
...
...
..etc.. for file operation
...
...
9ine
|
|
|
|
|
Hello all,
I have a fully functional Visual C++ .NET console application that draws an ASCII character map at run-time in a DOS window. How can I start a window and draw the map real-time to that window as opposed to the DOS window? I have very little experience with Windows graphics so any advice would be greatly appreciated on how to start the window, draw to it, etc ...
By the way, the map I need to draw is simply a grid with different squares in the grid having different colors.
Thanks guys and girls.
|
|
|
|
|
As Windows is an event based system, all drawing happens in an event called OnPaint. If you're using C++/CLI ( managed C++ ), you can use the FillRectangle method of the graphics object to draw rectangles of different colors to the screen. If this is an MFC app, then the CDC class has similar methods, but there's more work involved, and more margin for error, in terms of resource leaks, etc.
If you clarify which one it is, I'd be glad to offer more advice if needed.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hello Christian,
Thanks for the quick reply. If you bare with me a little longer, we'd be able to figure this out. Much appreciated.
I have Visual Studio .NET and the program I wrote is simply an MS-DOS console project that I started as an "empty project" in VS.NET (C++ Projects). This is my second time using VS, I have been programming in VC6 until recently. The program runs fine as an .EXE under DOS. It draws a grid map that is updated in a seperate thread from a class that the main thread updates, in other words, the main thread creates the map class, updates its members, and a drawing thread automatically and simultaneously reads from the map class object and updates the graphic grid.
Now, I would like to move the graphics to a window as opposed to the DOS console. It seems from your reply that managed C++ is a better way to do that, and given that I know neither managed C++ graphics nor C++/MFC, might as well learn C++/CLI and use that.
This is what I'm trying to do. Any further reply is much much appreciated.
Thanks.
|
|
|
|
|
One more thing. My impression is that VS.NET allows you to program parts of an application in C++, part in VB, and so on. Would having VB do the drawing be easier than drawing with Managed C++? And if so, how can VB see the map's class and draw from it?
Thanks Christian (and all).
|
|
|
|
|
Big_Goose wrote: My impression is that VS.NET allows you to program parts of an application in C++, part in VB, and so on.
Yes, if you write part of it in dlls. There's rarely a good reason to do this, I've only just done it for the first time ever ( I wrote some really complex image processing code in C++, and now I have a C# app that wants to call it ).
Big_Goose wrote: Would having VB do the drawing be easier than drawing with Managed C++?
Yes.
Big_Goose wrote: And if so, how can VB see the map's class and draw from it?
You'd have to write a MC++ dll that exposes methods to return the data. I'd be surprised if it wouldn't be easier to rewrite it in VB or C#.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Big_Goose wrote: Now, I would like to move the graphics to a window as opposed to the DOS console.
OK - if you've used standard C++ so far, I'd be inclined to use MFC. An MFC app should be able to run the code you've already written, and then you can use the OnPaint method of the View class to draw your grid.
managed C++ is what I still call what is now C++/CLI, because I've never used either
If you already know C++, then MFC is probably the way to go. If you want to learn VB.NET or C#, then you need to turn your C++ code into a DLL which returns the data that needs to be rendered, or convert it to one of those languages.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Is there any way to indiccate the insertion of duplicate key in STL map
babu.p
|
|
|
|
|
sarath_babu wrote: Is there any way to indiccate the insertion of duplicate key in STL map
You should ask this in the VC++ forum :-
VC++ forum[^]
|
|
|
|
|
Nish, C++/CLI is just plain too confusing for people. Most non MFC C++ questions seem to end up in here nowadays.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Christian Graus wrote: Nish, C++/CLI is just plain too confusing for people. Most non MFC C++ questions seem to end up in here nowadays.
Uhm, if a guy cannot differentiate between MFC and C++/CLI, it's worth asking the question as to whether he's ready for either (MFC or C++/CLI).
-- modified at 12:51 Tuesday 15th November, 2005
|
|
|
|
|
The point is that most people don't know what C++/CLI *means*, they assume it's a general C++ forum, as opposed to the Visual C++ forum, which they assume is for MFC and other 'visual' stuff.
That's my observation, I learned ages ago to look in here every day, even though I know very little about CLI.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Why on earth would a query about the C++ standard template library aka STL be in the microsoft foundation class or visual C++ forum?
I doubt that Alexander Stepanov and Meng Lee at Hewlett-Packard in Palo Alto, California, Dave Musser at General Electric's Research Center in Schenectady, New York, Andrew Koenig, and of course "Mr C++" himself, Bjarne Stroustrup at AT&T Bell Laboratories would put such a query in a MS forum?
And rather than give out a terse (bordering on rude) reply like Nish's why not suggest an answer and if it genuinely belongs in another forum educate the user so?
Dissapointed I am
|
|
|
|
|
i do agree perfectly... so here comes my question :
why do you continue the thread instead of ignoring it ?
if you don't agree with some things, use the voting to express your feeling about that... (which is what i am going to do now )
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Jeremy Thornton wrote: Why on earth would a query about the C++ standard template library aka STL be in the microsoft foundation class or visual C++ forum?
Because the STL forum also caters to ATL and WTL, yet is a ghost town ? A lot of people do not know what CLI is, and assume that this forum is for 'standard C++' questions.
Jeremy Thornton wrote: I doubt that Alexander Stepanov and Meng Lee at Hewlett-Packard in Palo Alto, California, Dave Musser at General Electric's Research Center in Schenectady, New York, Andrew Koenig, and of course "Mr C++" himself, Bjarne Stroustrup at AT&T Bell Laboratories would put such a query in a MS forum?
Who gives a toss what they would do ? People who are learning C++ are now required to understand it well enough to know which bits are STL before they are allowed to ask for help ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I'm sorry my views drove you to angry expletive I have tried to move what I thought was an important topic to the suggestions forum.
Christian Graus wrote: People who are learning C++ are now required to understand it well enough to know which bits are STL before they are allowed to ask for help ?
No that is the opposite of what I had intended to convey.
|
|
|
|
|
You have to test!
A STL map can only store one value per key.
If you use a second instance of the key it will supercede the existing one. If this is not intended then you should use a multimap.
You can see if a key is pre-existing by using the maps own find method and comaparing the result with the map's end iterator. If it reaches the end it isnt in the map
map<key,data>::iterator it
it = some_map_or_other.find( the_key );
if ( it != some_map_or_other.end() ) {
}
further, you can test if an item already exists in a map with the single arguement version of insert. This method returns a STL pair cpnsisting of an iterator & a bool. Now if the insertion was unsuccesful the bool will be false and the iterator will be at the duplicate key.
hope this helps?
-- modified at 8:46 Thursday 24th November, 2005
|
|
|
|
|
hi,
I'm trying to use a class that need to be shared in managed and unmanaged C++ code. Since the two style have different ways of handling strings, what should I do to manage string type of member variables? Thanks!
dummy808
-- modified at 23:18 Sunday 13th November, 2005
|
|
|
|
|
It's trivial to convert between CString and System::String, so there really shouldn't be any problem.
|
|
|
|
|
Thanks for the reply. But this is not just about conversion, it's about how to define string type members in the class. Managed code can only see managed part of the class member, which has to be of String * type, while unmanaged code can only see unmanaged part, which can only be of std::string or CString type. And if I create same member name for both managed and unmanaged part, the managed file would lose information when trying to use the object that's created in unmanaged code. hope I made myself clear enough. Thanks again for the help.
|
|
|
|
|
We recently upgraded some of our test machines to the .NET 2.0 framework, and discovered that this breaks some of the managed C++ DLLs we use in our install program. Unfortunately, when I try to debug these DLLs in VS.NET 2003, it crashes the IDE. (I'd love to know why so I can find the actual cause of the problem in the DLL, BTW, if anyone knows....) So I'm left with the alternative of trying to force the version of .NET that the DLL will load. I can't seem to find a way to do that either. Any hints?
|
|
|
|
|
If the DLLs were compiled using VC++ 2003, then they target .NET 1.1, so to run them on the target machine, it needs to have .NET 1.1 installed.
|
|
|
|
|
The DLLs were compiled using VC++ 2003, but apparently that doesn't mean they have to target .NET 1.1.
I wrote a little C program to load the DLL and call the function I want. (It exports all its functionality through C function calls so it can be called from an install program.) I have both .NET 1.1 and .NET 2.0 installed on my system. When I debug the DLL using the C program and VC++ 2003, the .NET 2.0 DLLs are the ones that get loaded, not .NET 1.1. Unfortunately, as soon as the CRT 8.0 DLL is loaded, the IDE crashes.
So far as I can tell, there's nothing that lets the DLL say what the minimum or maximum .NET version supported is....
|
|
|
|