|
I can't find the bug in this small code fragment.
I copied it straight from the book. It's probably 1 error causing a bunch of error message.
#include "stdafx.h"
#include <iostream>
#include <string>
#include "stdafx.h"
using namespace std;
const int MAX = 3;
struct Person{
string name;
int height;
};
int _tmain(int argc, _TCHAR* argv[])
{
Person p[MAX];
for (int x = 0; x < MAX; x++)
{
cout << "Enter person's name: ";
getline(cin, p[x].name);
cout << "Enter height in inches: ";
cin >> p[x].height;
cin.ignore();
}
cout << "Outputting person data\n";
cout << "======================\n";
for (x = 0; x < MAX; x++)
cout << "Person #" << x + 1 << "'s name is "
<< p[x].name << " and height is ";
<< p[x].height << endl;
return 0;
}
|
|
|
|
|
- Please quote your code properly - firstly, select the "Encode HTML tags when pasting" option below the text box and paste your code in, and secondly, please enclose it in <PRE> tags, to display it in a monospaced font.
- Try telling us at least some of the error messages
Also - that second #include "stdafx.h" looks wrong. If you're using precompiled headers, the second stdafx.h will cause the compiler and pre-processor to ignore all the #include statements that occur before the #include "stdafx.h"
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
modified on Wednesday, May 20, 2009 11:12 AM
|
|
|
|
|
there's a ";" that should not be there at the end of this line :
<< p[x].name << " and height is ";
This signature was proudly tested on animals.
|
|
|
|
|
jonathan warfield wrote: It's probably 1 error causing a bunch of error message.
Such as?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
jonathan warfield wrote: for (x = 0; x < MAX; x++)
for visual C++ 2003 onwards, variables defined inside for loopswill not be available outside. either you've to make int x declaration just before the for loop or for teh second for loop define as
for (int x = 0; x < MAX; x++)
jonathan warfield wrote: << p[x].name << " and height is ";
<< p[x].height << endl;
Please remove the unnecessary semi column at the end of first statement.
Anywayz start reading your favorite C++ Book
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
I am trying to understand something about MFC and resource files. By resource files, I mean files that end with the extension .rc. As I understand it, resource files can be used to create Menus and add short cuts. Please consider the following resource file:
<br />
IDR_MAINFRAME MENU<br />
{<br />
POPUP "&Output Options" {<br />
MENUITEM "&Create one", IDM_CREATE1<br />
MENUITEM "create two", IDM_CREATE2<br />
MENUITEM "create one", IDM_CREATE3<br />
}<br />
<br />
}<br />
<br />
IDR_MAINFRAME ACCELERATORS PRELOAD MOVEABLE<br />
BEGIN<br />
"C", IDM_CREATE1, VIRTKEY, CONTROL<br />
END<br />
Observe that the string “Create one” is prefixed by an &. The way I read the documentation (I am looking at the book Programming Window by Charles Petzold) the & is suppose to result in the C in Create being underlined. The fact that it is underlined will be a clue to the user that a short cut exists for that menu item. However, the character C is not being underlined. I am wondering what I am missing.
Important note: The book I mentioned above talks about C and developing code using the Windows SDK. The code I am writing is in C++ and it uses MFC. I am thinking that MFC is turning off the underline character.
Thanks
Bob
|
|
|
|
|
On Windows 2000 and up, the default behavior of underlining is a configuration option. Normally, they won't show underlining until you press the "alt" key.
|
|
|
|
|
Bob,
Thanks for the response. Is there way to set it up so that they show up by default? If so, please tell me how.
Thanks
Bob
|
|
|
|
|
It's usually in the display properties applet (right click on desktop and choose "Properties".
In Windows 2000, select the "Effects" tab and the configuration option is there.
In Windows XP, select the "Appearance" tab and then press the "Effects..." button to bring up the effects dialog. The configuration option is there.
|
|
|
|
|
Try pressing ALT? IIRC, Windows doesn't display the underlines until you press ALT.
Anyway - here's part of the menu code of an MFC SDI project with a classic menubar (selected on the User Interface Features pane of the MFC application wizard). It displays underlines correctly.
IDR_MAINFRAME MENU
BEGIN
POPUP "&File"
BEGIN
MENUITEM "&New\tCtrl+N", ID_FILE_NEW
MENUITEM "&Open...\tCtrl+O", ID_FILE_OPEN
MENUITEM "&Save\tCtrl+S", ID_FILE_SAVE
MENUITEM "Save &As...", ID_FILE_SAVE_AS
MENUITEM SEPARATOR
MENUITEM "&Print...\tCtrl+P", ID_FILE_PRINT
MENUITEM "Print Pre&view", ID_FILE_PRINT_PREVIEW
MENUITEM "P&rint Setup...", ID_FILE_PRINT_SETUP
MENUITEM SEPARATOR
MENUITEM "Recent File", ID_FILE_MRU_FILE1,GRAYED
MENUITEM SEPARATOR
MENUITEM "E&xit", ID_APP_EXIT
END
However, with VS2008, there is a second option for menus, which is "Use a menu bar and toolbar". This uses the menubar that comes with the "MFC Feature Pack" (it's a CMFCMenuBar[^]). This menubar doesn't appear to display underlines on the menubar (but does on the menu popups).
I hope this information clears up your issue...
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Staurt,
Thanks for the response. When I press the ALT key it works. However, when I run Microsoft Word,
I see that there are Menu items that are underlined without pressing ALT key. In Word they remain underlined even if I press the ALT key again. I would like the user to be able to see the underline without pressing the ALT key. Maybe I need to send the ALT key to the program. Please comment.
Thanks
Bob
|
|
|
|
|
BobInNJ wrote: I would like the user to be able to see the underline without pressing the ALT key.
Even though they may have Windows configured to do otherwise?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
David,
Thanks for the response. I am not sure how to answer your question. I know that when I run MS Word it comes up underlined. On the same system, when I run my program it does not until the user
hits the ALT key. I would like my program to be like MS Word. What should I do?
Bob
|
|
|
|
|
BobInNJ wrote: I would like my program to be like MS Word. What should I do?
In that case, you could always change the registy setting. See here for more.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
David,
Thanks for the response. I looked at the URL you suggested. I am not up on all this registry stuff so I may have missed the boat. Are you telling me that should set the field NoChangeKeyboardNavigationIndicators in HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Myapp
where the name of my application is Myapp.
If I have this right, is my install script suppose to set this up? By the way, the application I am writing does not currently set any entries in the registry. However, I have a feeling it should.
Bob
|
|
|
|
|
BobInNJ wrote: Thanks for the response. I looked at the URL you suggested.
Which was the wrong one. The registry value instead is:
HKCU\Control Panel\Desktop\UserPreferencesMask
Note the value of the 30th bit when you change the checked state of the "Hide underlined letters for keyboard..." checkbox.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
David,
Thanks for the response. If I understand your solution changing the registry value you suggest
will change it for every application on the system. That is not acceptable for my application. Maybe
I will just live with the default.
Bob
|
|
|
|
|
BobInNJ wrote: However, when I run Microsoft Word
I would tend to ignore Word (Office in general) - Office is notorious for a) not using the standard Windows components, and b) not following Windows user interface guidelines. And the trouble with bucking the standard is that you're never going to benefit from improvements made in later versions of the OS.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I got an assignmet 2 make a program finds fourier expansion the specifications are:
It is required to write a program in order to which takes a time expression as a string and perform all the necessary parsing on the expression and generate the fourier series expansion of this expression. THe program should be able to recieve the period of the wave under study even if it was a piecewise continuous expression.
Please any1 can help me with this?
|
|
|
|
|
maidy_19 wrote: Please any1 can help me with this?
most certainly
1) learn how to spell - don't use text speak either
2) learn how to use google - since this is an assignment likely you already have some resources, including your tutor, course-work
3) read the top question of this forum - the one that is titled "How to get an answer to your question"
when you've done that, post some code back here if you're still having trouble - we don't DO assignments for people - we help them with code - you havnt provided any yet.
'g'
|
|
|
|
|
So...what form is the time expression in? I'll presume it's something like x = sin(t)
The tricky bit is parsing the time expression. You will need an expression parser - you can find grammar for an expression parser in many of the grammars[^] on the ANTLR web-site[^]. Yes, I'd probably recommend you use ANTLR to generate the parser from a grammar - it even has its own IDE[^]! Might even suggest you use Java for the project, as ANTLR's Java support is more developed than its C/C++ support.
You then also need an automaton that can evaluate the expression you've parsed (probably with substitution of variable values). That will enable you to generate a time series. Generating the fourier series from that is trivial and left as an exercise for the reader
Spirit[^], which is another option for the parser generation, includes a calculator example that has a simple expression parser and an automaton for evaluating expressions, so that's another option.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
thanks Stuart you've been so much help
@ Garth J Lancaster : No comment
|
|
|
|
|
hi all :
As far as I know,to create a source file in visual studio 6.0 is not that easy as push a button,but: file->new->files->c++ sourcefile?please help me
|
|
|
|
|
wb_program wrote: As far as I know,to create a source file in visual studio 6.0 is not that easy as push a button
Maybe you need to get one of these[^]
|
|
|
|
|
There's a toolbar button for creating a new text file. When you save the file, give it a .cpp extension.
|
|
|
|