|
Here's a simple program I wrote just now:
#include "iostream.h"
#include "fstream.h"
void main()
{
int array;
ifstream infile ("binga");
infile >> array;
cout << array << endl;
}
the file binga looks like this:
1,2,3,4,5,6
a,b,c,d,e,f
one,two,three,four,five,six
So when I run the program, why do get the output as
-858993460
shouldn't the output just be
1
|
|
|
|
|
Your program does the equivalent of atoi("1,2,3,4,5,6") when enters infile>>array. You have to use space or CR to separate the numbers, not commas.
rechi
|
|
|
|
|
okay...
I just changed the file "binga" so it looks like this:
1 2 3 4 5 6
a b c d e f
one two three four five six
I ran the program again and I still got the output as
-858993460
as opposed to what it clearly should be:
1
what is going on here??
|
|
|
|
|
I think something wrong in your computer or your OS. Because in my computer, it's right. Output is: 1
Hung Son
A Vietnamese student
i-g.hypermart.net
dlhson2001@yahoo.com
|
|
|
|
|
Your main problem is simply that it's poorly written code.
For one, void main is NOT valid C++. For another, you don't initialise your variable, and for a third, you don't check to see if you've succeeded in opening a file, which you give only a relative path to.
int main()
{
int array = -1;
ifstream infile ("c:\binga");
if (infile.isopen())
{
infile >> array;
cout << array << endl;
}
else
cout << "Unable to open file";
}
I think you'll find it cannot open/find the file and is giving you the initial value of array.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"I'm somewhat suspicious of STL though. My (test,experimental) program worked first time. Whats that all about??!?!
- Jon Hulatt, 22/3/2002
|
|
|
|
|
I'm trying to create a custom toolbar to be used inside MS Word, however I'd like it to contain edit boxes, custom icons, etc. I'd like to do this using VC++/MFC, but I can only find references to "custom command bars" using VBA.
I'd like it to appear like Visual Assist's toolbar in DevStudio.
If anyone has any suggestions, or could point me in the right direction I'd be very grateful.
Alan.
|
|
|
|
|
-Create your toolbar.
-After that, you edit your resource by a editor, add any SEPARATOR neccesary in resource.
-In OnCreate(), use method SetButtonInfo(..) of the toolbar to change the width of edit box (or combobox...)
-Use Create(...) of edit box (or combo...) to create it onto the toolbar.
Hung Son
A Vietnamese student
i-g.hypermart.net
dlhson2001@yahoo.com
|
|
|
|
|
I'm trying to set the font in my CComboBox dropdown but am having
trouble getting it to work. The Combo Box has the right font information
but it doesn't seem to use it when displaying the text in the box when it
is dropped-down. Any thoughts on how to get it to work? Just for some background, I'm creating the CComboBox in the CMainFrame class and placing it on a toolbar to replace a button. I'm creating the CFont object and setting the font in the CComboBox in the CMainFrame::OnCreate() function. Not sure what I'm doing wrong.
|
|
|
|
|
Try SetFont() .
Mazy
"The path you tread is narrow and the drop is shear and very high,
The ravens all are watching from a vantage point near by,
Apprehension creeping like a choo-train uo your spine,
Will the tightrope reach the end;will the final cuplet rhyme?"Cymbaline-Pink Floyd
|
|
|
|
|
I tried that. I set the font with a font I created using CreatePointFont().
If I do a GetFont() on the CComboBox object, it returns the font information that I sent it using SetFont(), but the font in the CComboBox when it is drawn remains whatever the default font is when it is created.
|
|
|
|
|
You should check that your font object (example: m_font) must be declare as a class member. Don't declare it as a local variable.
Hung Son
A Vietnamese student
i-g.hypermart.net
dlhson2001@yahoo.com
|
|
|
|
|
I have commands that come into a program. Each command has a set of parameters depending on the type. So, I made a base class for the command and derived the the commands from this.
One of the operations was to convert the command to a string in a particular communication protocol and was named
toString(). Now I have to support another protocol. I could add another function to the base class (say toProtocol2String(), but is there a better way to do this?
The data to generate the strings are in the derived classes right now.
Or is there an entirely different way of looking at it?
Thomas
modified 29-Aug-18 21:01pm.
|
|
|
|
|
Hi!
Maybe: define base class for translating commands into strings:
class ICmdProtocol;
redefine method in the command class:
CString toString( IProtocol * );
And now, move the conversion implementation from command itself to protocol, or to command based on actual protocol.
You can always define current protocol for all commands too (as static pointer in base class for example).
Hope this helps
Mukkie
|
|
|
|
|
If your set of commands is relatively fixed, you can take advantage of a design pattern called visitor. Define an abstract class CommandVisitor like this:
class CommandVisitor
{
virtual void visit(Command1&);
virtual void visit(Command2&);
...
virtual void visit(Commandn&);
} Change the Command base class to match the visit methods with a corresponding accept method:
class Command
{
...
virtual void accept(CommandVisitor&)=0;
} Now, each Command , when issued an accept by some generic visitor, simply derives to the corresponding visit overload:
class Command2: public Command
{
void accept(CommandVisitor& visitor)
{
visitor.visit(*this);
}
} So far so good. Now you can turn protocol #1 into a visitor by moving there the code previously found on the Command s themselves:
class Protocol1:public Visitor
{
string result;
string toString(Command& command)
{
command.accept(*this);
return result;
}
void visit(Command1 &command)
{
result=...;
}
...
void visit(Commandn &command)
{
result=...;
}
} Got the idea? You moved the protocol to string stuff to a loosely coupled visitor. To implement a second protocol just create a different visitor in the same way. A little hard to grasp at first, but it can greatly improve your design in the long term. This code is just shown as an indication, it surely won't even compile. Make a search on "Visitor pattern" on the web for lots of further info.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
This is excellent.
Exactly the kind of thing I wanted.
I am not very familiar with design patterns and was hoping that someone would give an answer based on a pattern.
Thank you very much
Thomas
modified 29-Aug-18 21:01pm.
|
|
|
|
|
If you're interested in design patterns, the standard reference is "Design patterns" by Gamma et al. The style is a little dry for my taste, but it is definitely worth reading and having handy.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
No kidding. Great book for insomia.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
Anyone have any ideas on how to programmatically convert an Excel file to a Adobe PDF file. I need to automate the proccess, but have a feeling that if I use distiller, I will not be able to specify a file name for it to work without any user inpput, other than triggering the job.
Any ideas?
Giles
|
|
|
|
|
Don't you want to use Acrobat Writer as a printer to print Excel to PDF?
I have another way: if you can get text from Excel with your code, use PDFLIB4.0 to convert to PDF
Hung Son
A Vietnamese student
i-g.hypermart.net
dlhson2001@yahoo.com
|
|
|
|
|
dlhson wrote:
Don't you want to use Acrobat Writer as a printer to print Excel to PDF?
You could be write. I have used the print function before, but as I remember, once you print, it pops up with a save as dialog. Or at least I think so. Is there a parammeter you can set from VBA\ via COM, to automate the whole thing. The thing is I need to use the formatting from Excel.
Do you have a link to PDFLIB4.0? I've seen a utility in Perl, to convert a text file to PDF, but I also need the formatting and calculations that I would find easier in Excel.
Thanks,
Giles
|
|
|
|
|
Hi All,
Can I change the text of the Cancel button to something else.I hate having a whole new dialog up where I need MessageBox kind of functionality except for the Cancel button text being something else.MessageBoxIndirect also doesnt seem to help me much.
VC 6.0 SDK.
Thanks for your help.
cheers
Sriram M R
|
|
|
|
|
I think you'd have to write your own dialog.
However, what woudld be really neat would be a more generic MessageBox type dialog that can be used in these kinds of situations... that'd make a great article, you know...
recursive adj. See RECURSIVE.
|
|
|
|
|
Well, what do you know? There *is* such an article already posted:
TCX Message Box
recursive adj. See RECURSIVE.
|
|
|
|
|
Thanks.I had a look at it before.But thats too heavy duty class for my app.
Maybe I will design a small dialog myself................
Cheers and ciao,
Sriram M R
|
|
|
|
|
You could install a hook on the message box and capture the WM_SETTEXT message for the child window (cancel button).
Jeremy L. Falcon
"The One Who Said, 'The One Who Said...'"
[My Latest Article]
Homepage: imputek.com
|
|
|
|