|
Delete this immediately
we saw your first question, so, no need to repost, no need to start a new thread to stay on top, and no need to spam the board
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
|
|
|
|
|
I see at least three separate issues here. What exactly are you having trouble with:
1) opening a file
2) responding to a button click
3) reading from an edit control
Be specific with your request(s) and you'll get way more help.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
you can use (CFile /CArchive) to open file and use SetWindowText to set filename in editbox
and for change color from editbox use OnCtlColor.
whitesky
|
|
|
|
|
i would like to read the values of two col and some rows (more than two)from the *.txt file and to find sum of those cols separately.
for ex
1 2
2 3
respective values are 3 and 5.
kindly provide me solution if any body got some idea.
regards
saisameer
divi saisameer
|
|
|
|
|
One way is to Create a strucure as
struct numberStruct{
int m_iX;
int m_iY;
};
Now while writing and reading using FILE object write/read the complete structure using fwrite and fread.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
This won't work at all: you will write binary data to the file which is not what the OP wanted to do.
Cédric Moonen
Software developer
Charting control
|
|
|
|
|
it wont work. he has a text file, not a binary one...
and your method doesn't take in account the space delimiters between the values in one line...
however, the idea of the struct can be a good memory representation, once the file is read, to load its content in memory
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
|
|
|
|
|
Overlooked "TEXT FILE"
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Try this:
---------
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
int main(int argc, char* argv[])
{
using namespace std;
// Open the file.
ifstream fs("C:\\a.txt");
if (!fs)
{
cerr << "Couldn't open file!" << endl;
return 1;
}
// Read in the lines and sum them.
string line;
while ( getline(fs, line) ) // Get a line.
{
// Sum each number in this line.
int num;
int sum = 0;
istringstream iss(line);
while ( iss>>num )
{
sum += num;
}
// Output the result.
cout << "Total: " << sum << endl;
}
return 0;
}
Steve
|
|
|
|
|
For starters:
int n1, n2;
FILE *pFile = fopen(..., "rt");
while (! feof(pFile))
{
fscanf("%d %d", &n1, &n2);
}
fclose(pFile);
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Here is a very basic solution:
<br />
void main()<br />
{<br />
vector<int> Col1, Col2;<br />
ifstream fin("mytext.txt");<br />
while (!fin.eof())<br />
{<br />
int c1, c2;<br />
fin >> c1 >> c2;<br />
Col1.push_back(c1);<br />
Col2.push_back(c2);<br />
if (fin.eof())<br />
{<br />
break;<br />
}<br />
}<br />
<br />
int Column1Total = accumulate(Col1.begin(), Col1.end(), 0, add<int>()); <br />
int Column2Total = accumulate(Col2.begin(), Col2.end(), 0, add<int>());<br />
}
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Hi,
I need to dynamically create 3-5 radio button on a dialog box in vc++6 using mfc.
Please can somebody help me. I am just not getting it.
Thanks,
Tara
Fortitudine Vinsinues!
|
|
|
|
|
Having you considered using the CButton::Create() method? What code do you have that is not working?
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
This is what I have done:
void CBudget::CreateRadioButtons()<br />
{<br />
CButton newRadio;<br />
CRect rect;<br />
<br />
#define IDD_NEWR1 0x1234<br />
<br />
rect.bottom=150;<br />
rect.top=100;<br />
rect.left=100;<br />
rect.right=250;<br />
<br />
newRadio.Create(_T("Home"), WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_RADIOBUTTON, rect, this, IDD_NEWR1);<br />
but nothing showsup. I have called
CreateRadioButtons() in OnInitDialog()
Fortitudine Vinsinues!
|
|
|
|
|
I think you should move the CButton newRadio; declaration to the class body. Make it as a data member of CBudget . Otherwise your control is deleted after finishing the CreateRadioButtons function.
-- modified at 9:50 Thursday 22nd June, 2006
Another solution is to put your controls in the dialog using Dialog editor, making them invisible. When you need to show them, just make visible. In this way is easier to define event handlers for your controls.
|
|
|
|
|
Ah yes! It worked. Thanks.
Now, if I create 3 buttons, how do set then as a group. i.e how do I use them? How do I get which radio button has been selected.
Fortitudine Vinsinues!
|
|
|
|
|
TheinstruTara wrote: ...how do set then as a group...
Use the WS_GROUP style for the first one.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Add Handler's for them in message map section
ON_BN_CLICKED(ID_RADBUTTON ,OnRadioClicked) // Defined ID_RADBUTTON
//in the header file
afx_msg void OnRadioClicked();
//and in the cpp file
void CCheck1Dlg::OnRadioClicked(){
//Some COde
}
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
The problem is I do now know how many will be needed. It dependes upon how many budget entries a user makes.
Fortitudine Vinsinues!
|
|
|
|
|
Can I not create another radio button using the same CButton object, newRadio?
Fortitudine Vinsinues!
|
|
|
|
|
Yes, but newRadio will need to be a pointer.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
A CButton object is for one radio button. If you need more, define another CButton data member.
In case of variable number, you can define a dynamic collection of such objects. For instance, you can try CTypedPtrArray< CObArray, CButton * > .
You have to create new buttons with new CButton , then call Create , and then add to collection with Add . Do not forget to delete the unneded buttons with delete .
|
|
|
|
|
Oh no I just dont have the time to figure out that. I guess I use good'ol combo box or a list box instead!!
Thanks a lot for the help everybody. I will definitly try it out later, and maybe post an article;)
Fortitudine Vinsinues!
|
|
|
|
|
Move the line CButton newRadio to the header file Budget.h
What i think is that you are going to create these buttons dynamically and more than once. So it would be better for you to change the function definition to
CreateRadioButton(int,int,int,int);// Specifying where to place the buttons.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
TheinstruTara wrote: CButton newRadio;
This object has function-level scope. It needs to be a member of the CBudget class.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|