|
You will probably need to use Subclassing[^] to capture events sent to the statusbar.
It's time for a new signature.
|
|
|
|
|
Hi,
I'm using the following code in visual studio 2008:
std::vector< double >::iterator location;
location=std::find(vec.begin(),vec.end(),0.);
and I'm getting the error:
error C2679: binary '=' : no operator found which takes a right-hand operand of type 'std::_Vector_iterator<_Ty,_Alloc>' (or there is no acceptable conversion)
My header files are as follows (I know all these aren't necessary for this small portion of code, but the rest of my code requires the additional headers):
#include "stdafx.h"
#include <algorithm>
#include <iostream>
#include <vector>
#include <fstream>
#include <string>
#include <ostream>
Does anyone know how to fix this? Is it possibly a visual studio project setting
Thanks!
|
|
|
|
|
A fresh VC++ 2008 console project compiles the following code just fine:
#include <vector>
#include <algorithm>
int main()
{
std::vector<double> vec;
std::vector< double >::iterator location;
location=std::find(vec.begin(),vec.end(),0.);
}
Also, be careful when comparing floating-point numbers[^]
|
|
|
|
|
|
Hi everyone,
I'm using a vector of vectors to mimic a matrix using the following:
vector < vector <long double> > data_matrix;
I then add "rows" using the following:
for (int z=0;z<13;z++)
data_matrix.push_back(vector <long double>());
Next, I load the appropriate values (from an input file) into the vector of vectors (some the values will be zeroes).
What I'd like to do, is to search a particular "column" for zeroes and eliminate them in that column as well as the corresponding entries in the adjacent columns (so in effect, eliminate an entire row). I've figured out how to delete zeros from any given vector in the vector of vectors using:
bool IsEven (double d)
{
return (d) == 0;
}
data_matrix[0].erase(std::remove_if(data_matrix[0].begin(),data_matrix[0].end(),IsEven), data_matrix[0].end());
Does anyone know how to do this
The number of entries in each of the columns are the same.
Thanks!
modified on Friday, May 21, 2010 12:43 PM
|
|
|
|
|
Can you give us an example of what happens when you, for example, reduce a 3 by 3 matrix like:
1 1 1
0 2 2
3 3 3
Would you expect to end up with the following matrix?
1 1 1
3 3 3
If so you can do it with remove_if on the vector of rows - you remove any row that has a zero element in it. The predicate will have the form:
bool contains_zero( const std::vector<long double> &row )
{
....
}
Cheers,
Ash
PS: If you're using a compiler that supports them you can write the predicate as a lambda rather than as a function.
PPS: Just out of interest you can get rid of the loop:
for (int z=0;<13;z++) data_matrix.push_back(vector <long double>());
Have a look for a constructor for vector that takes a size or consider using std::generate_n to do it all in one fell swoop.
|
|
|
|
|
Hi Ash,
Thanks for replying. You're example matrix is what I'd expect. The way my vector of vectors is set up is that each of the vectors actually contains the data from the particular column (instead of row). This is why I seem to be having trouble.
For example (when referring to your sample matrix):
vector[0] would contain 1 0 3
vector[1] would contain 0 2 2
vector[2] would contain 3 3 3
So for example, the code and predicate that I previously posted which used "remove_if" would make vector[0] = 1 3 which would then give:
1 1 1
3 2 2
3 3
but not:
1 1 1
3 3 3
I should have mentioned that key piece of information (that the vectors hold columnar data instead of row date), sorry about that.
Any ideas for this scenario
Thanks,
|
|
|
|
|
Ouch, it's a bit messier but...
- for each column use std::find to locate any zeros. Record the indices of the rows the zeros are in somewhere, maybe another vector or a perhaps a set. (std::find returns an iterator, you'll have to subtract column.begin() from that to get the index from the iterator).
- for every row there's a zero in, zero every column element in that row.
- for each column use the combination of std::remove_if and std::erase you presented in the question to eliminate the zeros.
Hope that's clear enough - if not feel free to ask what I'm wittering on about,
Ash
|
|
|
|
|
Thanks Ash,
Sounds good, I'll give this a try.
|
|
|
|
|
Hi,
How to change the window title in SDI application dynamically.
Ex : title is MyApp - untitled
I want to change MyApp to some other text.
I can change untitle to any other value but i want to change MyApp
to some other text.
Please help me
|
|
|
|
|
Check out the IDR_MAINFRAME string resource.
"One man's wage rise is another man's price increase." - Harold Wilson
"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
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Yes IDR_MAINFRAME string variable will work
but I want to change dynamically?
|
|
|
|
|
Sakhalean wrote: but I want to change dynamically?
Have you tried calling SetWindowText() from within the frame's ActivateFrame() or OnCreate() method?
"One man's wage rise is another man's price increase." - Harold Wilson
"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
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
SetTitle()[^] is the most common method for changing it dynamically.
It's time for a new signature.
|
|
|
|
|
Hi,
It is not working.
SetTitle will change untitled to some value
but MyApp will won't change.
How to change MyApp name dynamically
|
|
|
|
|
Sorry, I'm very rusty on my MFC, try SetWindowText()[^].
It's time for a new signature.
|
|
|
|
|
Try that ^.
Life is a stage and we are all actors!
|
|
|
|
|
You can solve the problem inspired from here. It's working 100%.
|
|
|
|
|
Thank you.
Any have i have solved like this
CMainFrame* pFrame = (CMainFrame* )AfxGetMainWnd();
CSIRBaseView* pView = (CSIRBaseView* )pFrame->m_pNewView;
CSIRBaseDoc* pDoc = (CSIRBaseDoc* )pView->GetDocument();
CString strDoc, strFrame;
pFrame->GetWindowText( strFrame );
strDoc = "MyApp";
strDoc += strFrame.Right( strFrame.GetLength() - strFrame.Find( "-" ) +1 );
pFrame->SetWindowText( strDoc );
|
|
|
|
|
Thank you for your sharing, it's really useful for me.
|
|
|
|
|
In my app I automate word. In my main window I have buttons for going to first/prev/next/last page. When the user clicks on them I want to make word programatically go to the page. I do this for prev/next
m_Application.CreateDispatch("Word.Application");
.......
m_Browser.AttachDispatch(m_Application.get_Browser());
.......
void CMyView::OnPagesGoToPrevious()
{
m_Browser.Previous();
}
void CMyView::OnPagesGoToNext()
{
m_Browser.Next();
}
But there are no methods for going to first/last page. How do I implement it?
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
I did a quick check to see what Word (V12) would do if I recorded the 'keyboard equivalent' methods as a macro, and it put this
Selection.EndKey Unit:=wdStory
(for Control-End, go to end of (document?) ) in the macro and this
Selection.HomeKey Unit:=wdStory
for Control-Home to go to the start of the (document?)
So maybe you need to start with a Selection Object .. the MSDN references are a pita though - I couldnt make head nor tail looking at this ... http://msdn.microsoft.com/en-us/library/bb288734(v=office.12).aspx[^]
good luck
|
|
|
|
|
Hi,
I have an application working in DualMonitor also.But in my application.there is no Frame.So,manaully i coded in my application to move to secondary window with one shortcut key.
What my problem is,
In my coding I coded to move applcation by this follwing code:
pWnd->SetWindowPos( NULL, -1024, 0, 0, 768, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
But it works only when the secondary monitor is in Leftside of primary and resolution settings like this numbers.
But i failed to move it the secondary monitor in right side.
So i use the following to get virtual scrren dimesnions
GetSystemMetrics( SM_XVIRTUALSCREEN )
GetSystemMetrics( SM_YVIRTUALSCREEN )
GetSystemMetrics( SM_CXVIRTUALSCREEN )
GetSystemMetrics( SM_CYVIRTUALSCREEN )
it returns as (-1024,0,2304,768).
it returns whole width of two monitors.
But i want only the dimesnions of secondary monitor.
How can i do that?
Anu
|
|
|
|
|
Couldn't you take the width of both monitors and subtract the width of the primary monitor?
You might could also use a combintion of EnumDisplayDevices() and EnumDisplaySettings() .
"One man's wage rise is another man's price increase." - Harold Wilson
"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
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Hi,
AFAIK there are three ways to go:
1.
make some assumptions on the monitor situation; such as they are next to each other, trying to form one larger desktop. Then some simple arithmetic may get you what you want (kind of: x2 stretches from width1 to width1+width2). But that would fail if they were configured vertically.
2.
use GetSystemMetric() to find the size of the desktop; this is the bounding rectangle of all monitors present, however there could be holes in it, when you have a rectangular arrangement (say 3*2) with some monitor missing, or when the resolutions aren't all the same.
see SM_CXVIRTUALSCREEN and SM_CYVIRTUALSCREEN
3.
use some Win32 function, maybe EnumDisplayDevices(), to find out how many monitors there are, whether they all are part of the desktop, and if so, where they are in the uniform coordinate system.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
modified on Friday, May 21, 2010 9:05 AM
|
|
|
|