|
binary_search assumes the range being searched is ordered. Insert this line before remove_copy_if :
sort(dictionary.begin(),dictionary.end()); and the program will work just fine.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks, Joaquín buddies!
George
|
|
|
|
|
Hi, everyone!
Here is my simple STL program, it is a spell-checker.
The program copy every word of text to output
that is not in the dictionary. I have added all the source
codes and error messages below. My IDE is VC6.0.
Source Codes:
--------
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <fstream>
using namespace std;
template <class bidirectional_iterator, class T>
class nonAssocFinder {
public:
nonAssocFinder(bidirectional_iterator begin,
bidirectional_iterator end) :
_begin(begin), _end(end) {}
bool operator() (const T& word) {
return binary_search(_begin, _end, word); }
private:
bidirectional_iterator _begin;
bidirectional_iterator _end;
};
void main()
{
typedef vector<string > dict_type;
ifstream dictFile("dict.txt");
ifstream wordsFile("words.txt");
dict_type dictionary;
copy (istream_iterator<string>(dictFile),
istream_iterator<string>(),
back_inserter(dictionary));
remove_copy_if (
istream_iterator<string>(wordsFile),
istream_iterator<string>(),
ostream_iterator<string>(cout, "\n"),
nonAssocFinder<dict_type::iterator,
dict_type::value_type>
(dictionary.begin(), dictionary.end()));
}
--------
Warning and error messages:
--------
C:\Program Files\Microsoft Visual Studio\MyProjects\testDict\testDict.cpp(45) : warning C4786:
'std::reverse_iterator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const
*,std::basic_string<char,std::char_traits<char>,std::all
ocator<char> >,std::basic_string<char,std::char_traits<char>,std::allocator<char> > const
&,std::basic_string<char,std::char_traits<char>,std::allocator<char> > const *,int>' : identifier was truncated to '255'
characters in the debug information
C:\Program Files\Microsoft Visual Studio\MyProjects\testDict\testDict.cpp(45) : warning C4786:
'std::reverse_iterator<std::basic_string<char,std::char_traits<char>,std::allocator<char> >
*,std::basic_string<char,std::char_traits<char>,std::allocator
<char> >,std::basic_string<char,std::char_traits<char>,std::allocator<char> >
&,std::basic_string<char,std::char_traits<char>,std::allocator<char> > *,int>' : identifier was truncated to '255' characters
in the debug information
c:\program files\microsoft visual studio\vc98\include\iterator(176) : error C2679: binary '>>' : no operator defined which
takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >'
(
or there is no acceptable conversion)
c:\program files\microsoft visual studio\vc98\include\iterator(176) : while compiling class-template member function
'void __thiscall std::istream_iterator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char>
>,char,struct std::char_traits<char> >::_Getval(void)'
--------
How to resolve the trouble?
Thanks in advance,
George
|
|
|
|
|
The warning is a problem with the compiler not being able to cope with the very long symbol names generated when instantiating STL containers. You can safely mask it by inserting
#pragma warning(disable: 4786) at the beginning of your file. As for the second problem, I'm not 100% sure but probably inserting
#include <string> will help. Good luck.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks, Joaquín buddies!
George
|
|
|
|
|
I am tring to get this Manta Web sample to work. It does to start with
but when I try to create a new account it gives the error
OLE DB ERROR:
CAddUser::OpenRowset() returned: 0x80004005
Here is the code.
HTTP_CODE AddUser()
{
// Add the user to the database
CAddUser addUser;
lstrcpy(addUser.m_szFirstName, m_strFirstName);
lstrcpy(addUser.m_szLastName, m_strLastName);
lstrcpy(addUser.m_szEmail, m_strEmail);
lstrcpy(addUser.m_szLogin, m_strLogin);
lstrcpy(addUser.m_szHint, m_strHint);
HRESULT hr;
// don't store the real password. only store a one-way encrypted hash
DWORD dwSaltLen = 4;
DWORD dwPasswordLen = DB_MAX_STRLEN;
hr = HashSecret(
(const BYTE*) (LPCSTR) m_strPassword1, m_strPassword1.GetLength(),
(BYTE*) addUser.m_szSalt, dwSaltLen,
(BYTE*) addUser.m_szPassword, dwPasswordLen);
if (FAILED(hr))
return HTTP_FAIL;
addUser.m_szSalt[dwSaltLen] = 0;
addUser.m_szPassword[dwPasswordLen] = 0;
hr = addUser.OpenRowset(m_dataConnection, NULL);
if (hr != S_OK)
return DatabaseError("CAddUser::OpenRowset()", hr);
// Send the confirmation email
#if defined(SEND_CONFIRMATION_MAIL)
if (!SendMail())
return SMTPError();
#endif
// Create the MantaWeb persistant cookie
WritePersistCookie(addUser.m_szLogin, addUser.m_szFirstName, (m_bRememberPass) ? "1" : "0");
// Send the response page
CString strHTML;
LoadHtmlFromResource(MAKEINTRESOURCE(IDR_CONFIRM), strHTML);
strHTML.Replace("[NAME]", m_strFirstName);
strHTML.Replace("[EMAIL]", m_strEmail);
strHTML.Replace("[LOGIN]", m_strLogin);
m_HttpResponse << strHTML;
m_HttpResponse.Flush();
return HTTP_SUCCESS_NO_PROCESS;
}
It gives trouble at hr = addUser.OpenRowset(m_dataConnection, NULL);
It returns FAIL.
Thank You
Bo Hunter
Bo Hunter
|
|
|
|
|
I could not even get this example to compile. I downloaded it directly from Microsoft and have the current SDK, and VS.NET, however, it wouldn't compile.
this sample is evil, manta web is evil.
R.Bischoff | C++
.NET, Kommst du mit?
|
|
|
|
|
Hi,
I am working on the application wherein i have to download the file from the URL mentioned.
But the problem is I have to support the resume operations for broken downloads...using mfc.
How do i do this using mfc. Please give me your inputs.
TIA,
Snowy
|
|
|
|
|
I would start with MFC class CInternetSession.
I would prepare a CString(which creates a temp file on harddrive if Isesion stops) and download the html, have it write to the string in chunks and always GetLengh() so if the download stops, you know where to resume later.
I don't have any professional experience with this type of thing but I have used the CInternetSession. That's where I would start, I don't know if it's the best logic though. Ask for a second opinion, if you have time
Later, JoeSox www.joeswammi.com
Load my Sig here.....
|
|
|
|
|
This ATL/WTL/STL forum so my suggestion is to use ATL for it. I believe it could be safely mixed with MFC. ATL class CBindStatusCallback does most of what you are looking for.
|
|
|
|
|
You have to add a Range: header to your download request. Lets say you got 1000 bytes of a file from a previous request. Here's what you need to do
GET /somefile.zip HTTP/1.1
Range: bytes=1000-
which will start at offset 1000 bytes into the file.
Todd Smith
|
|
|
|
|
Hi,
I'm writing a program that is supposed to detect the configuration of outlook express (installed in the machine where the application is run). When I say configuration I mean the pop and smtp servers, at least. Now, reading the registry I can get that info, but the registry keys vary according to the user (right?), because different user profiles (windows 2000) can have different outllo express configurations. What I really need is to detect the configuration for the user that is executing the application.
For Example, my reg key for this is in:
HKEY_USERS\S-1-5-21-3046562155-3082545408-3971354878-2339\Software\Microsoft\Internet Account Manager\Accounts\00000001
Now, what is this number: "S-1-5-21-3046562155-3082545408-3971354878-2339"? I don't think it's going to be the same in different machines, therefore I don't seem to be able to detect what I want using the registry.
Any ideas?
Thanks!
-- narada
|
|
|
|
|
That's what HKEY_CURRENT_USER is for, it's mapped to the current user's key in HKEY_USERS .
--Mike--
The Internet is a place where absolutely nothing happens.
-- Strong Bad
1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
Sorry, this is wrong forum, right? Anyway, I appreciate your answer, still I don't know if the key is going to be the same in another machine, so how could read that programmatically?
Thanks anyway,
-- narada
|
|
|
|
|
From your first post (with my emphasis):
What I really need is to detect the configuration for the user that is executing the application.
Again, that is what HKEY_CURRENT_USER is for. The system automatically maps that hive to the key under HKEY_USERS that corresponds to the user making the call. You never have to access HKEY_USERS at all.
--Mike--
The Internet is a place where absolutely nothing happens.
-- Strong Bad
1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
Yes, I see. Sorry about my confusion!
Thanks so much, I did it this way and its working fine!
-- narada
|
|
|
|
|
I try to catch events like this
class ATL_NO_VTABLE CTBar : <br />
public CComObjectRootEx<CComSingleThreadModel>,<br />
public CComCoClass<CTBar, &CLSID_TBar>,<br />
public IDispatchImpl<ITBar, &IID_ITBar, &LIBID_ATLToolBarLib, 1, 0>,<br />
public IDispEventImpl<1,CTBar,&__uuidof(DWebBrowserEvents2),&LIBID_SHDocVw>,<br />
public IObjectWithSiteImpl<CTBar><br />
public ......<br />
{<br />
<br />
BEGIN_SINK_MAP(CTBar)<br />
SINK_ENTRY_EX(1,__uuidof(DWebBrowserEvents2),DISPID_NEWWINDOW2,OnNewWindow)<br />
END_SINK_MAP()<br />
.....<br />
<br />
IUnknown* m_pSinkUnk;<br />
IWebBrowser2* m_pWebBrowser2;<br />
LPDWORD cookie;<br />
STDMETHOD (SetSite) (IUnknown*);<br />
STDMETHOD (OnNewWindow) (IDispatch** &ppDisp,VARIANT_BOOL* &Cancel);<br />
.....<br />
};<br />
<br />
<br />
STDMETHODIMP CTBar::SetSite(IUnknown* punkSite)<br />
{<br />
.....<br />
IServiceProviderPtr pServProv(punkSite);<br />
pServProv->QueryService(SID_SWebBrowserApp, IID_IWebBrowser2,(void**)&m_pWebBrowser2);<br />
this->QueryInterface (IID_IUnknown, (LPVOID*)&m_pSinkUnk);<br />
AtlAdvise(m_pWebBrowser2,m_pSinkUnk,__uuidof(DWebBrowserEvents2),cookie);<br />
.....<br />
}
but i can't. Where's the problem in this code?
|
|
|
|
|
Hi, everyone!
I am puzzled at some words taken from my STL
tutorial. Here are the words at which I am puzzled.
--------
Note: For two input iterators a and b, a == b implies *a == *b.
For istream iterators, this condition doesn't hold.
--------
My opinion is,
--------
Two istream iterators are equal if :
both are end-of-stream iterators and this can no longer be read, or
both can read and use the same stream
from "The C++ Standard Library" by Josuttis.
--------
So I think whether a and b are equal has nothing to do
with *a and *b. Another question, "input iterators" is
different from "istream iterators"? I think they are the same.
Am I correct? Who can give me an explanation?
Better with an example.
Thanks in advance,
George
|
|
|
|
|
Note: For two input iterators a and b, a == b implies *a == *b.
This is just false. The only requisite about == for input iterators is that it should be an equivalence relation.
both are end-of-stream iterators and this can no longer be read, or
both can read and use the same stream.
This is absolutely right.
Another question, "input iterators" is different from "istream iterators"?
No, an istream_iterator is an input iterator, but an input iterator is not necessarily an istream_iterator (for instance, a pointer is an input iterator).
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hi, Joaquín buddies!
As you said,
--------
This is just false. The only requisite about == for input iterators is that it should be an equivalence relation.
--------
Do you mean that what tutorial is saying is not correct?
What puzzled me most is the meaning of "equivalence relation". What do you mean "equivalence relation"?
Because I think I can give you an example when a == b, while the same time *a != *b.
Thanks in advance,
George
|
|
|
|
|
Of course you can give that example An equivalence relation, if you remember from your Math classes, is just a relation being reflexive, symmetric and transitive. With regard to our particular problem, this means thati==i always evaluates to true ,
- if
i==j then j==i ,
- if
i==j and j==k then i==k .
As you can see, expressions of the type *i are not involved in this definition.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hi, Joaquín buddies!
I think you mis-understand my question. My
origin question is, the tutorial said,
--------
if( (i == j) && (i and j are both input iterators) )
then
(*i == *j)
endif
--------
My question is not that I do not understand what means
"equivalence relation".
What is your opinion about the tutorial? Is it correct?
Thanks in advance,
George
|
|
|
|
|
--------
if( (i == j) && (i and j are both input iterators) )
then
(*i == *j)
endif
-------- This is false. The tutorial is wrong. The only requisite about == for input iterators in general is the equivalence relation stuff, as you pointed out before.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks, Joaquín buddies!
George
|
|
|
|
|
I have what is probably a simple question, but I am stuck and need help. I am trying to create an Options dialog box for an app. I am using WTL to create the app. I have added the tab control, but I need a quick way to select the controls for each page. In VB I would create a group control and add the controls to the group, then show and hide the group as needed. I can't seem to make this work in WTL (probably doing something wrong with adding the controls to the group). I also, think that I might be able to use a dialog resource like a property sheet, but I am at a loss at how to get this added to the Tab Control. What is the best way to proceed?
Thanks for any help you can give.
Leo T. Smith
|
|
|
|
|