|
Sorry, I didn't look in detail at your code, but maybe a Trie[^] structure is what you need here.
|
|
|
|
|
I'm struggling with some USB devices that work like a serial devices.
The driver used is UsbSer.sys.
So I register for device notifications and in OnDeviceChange() I get the "filename" for the device so I can open it with ::CreateFile() .
I now need a way to get the vendor and product ids from the device, preferably by using ::DeviceIoControl() or the Setup API.
Actually it's a composite device so it registers as a few different devices.
This means I can access it using different drivers, using different "filenames", but it should be used as a serial device. Even if I got the vendor id by using another device class I haven't found a way to map that device to the serial driver for the same device.
Is there some I/O control code or a neat method using the setup API I've overlooked, I would be most grateful to be pointed in the right direction.
Previously the "filename" has been parsed since it seemed to be built using the vendor and product ids, but this method breaks when the device presents itself as a composite device. So I assume using the registry is not the way to do it.
Ideas anyone?
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Hey all,
I've got this really annoying problem I just can't solve - I'm trying to print the elements of my array of strings, but I can't make it, I've tried several different ways.
Here's my code, which won't compile:
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
string a[]={"a", "b", "c", "d", "e"};
cout << a[3];
return 0;
}</iostream>
I've been googling around for quite a while now and this code looks so right to me.
And one other thing; how can i create a string from several elements of this array?
Thx
/Joplinazz
|
|
|
|
|
why doesn't it compile ?
any compiler/linker errors ?
|
|
|
|
|
Well, here's the huge description of the error I'm getting:
c:\andreas\programmering\cpp\arraytesting\arraytesting\arraytesting.cpp(11) : error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)
c:\program\microsoft visual studio 9.0\vc\include\ostream(653): could be 'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits><char>>(std::basic_ostream<_Elem,_Traits> &,const char *)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program\microsoft visual studio 9.0\vc\include\ostream(700): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits><char>>(std::basic_ostream<_Elem,_Traits> &,char)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program\microsoft visual studio 9.0\vc\include\ostream(738): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits xmlns:std="#unknown"><char>>(std::basic_ostream<_Elem,_Traits> &,const char *)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program\microsoft visual studio 9.0\vc\include\ostream(785): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits><char>>(std::basic_ostream<_Elem,_Traits> &,char)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program\microsoft visual studio 9.0\vc\include\ostream(909): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits><char>>(std::basic_ostream<_Elem,_Traits> &,const signed char *)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program\microsoft visual studio 9.0\vc\include\ostream(916): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits><char>>(std::basic_ostream<_Elem,_Traits> &,signed char)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program\microsoft visual studio 9.0\vc\include\ostream(923): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits><char>>(std::basic_ostream<_Elem,_Traits> &,const unsigned char *)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program\microsoft visual studio 9.0\vc\include\ostream(930): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits><char>>(std::basic_ostream<_Elem,_Traits> &,unsigned char)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program\microsoft visual studio 9.0\vc\include\ostream(170): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_ostream<_Elem,_Traits> &(__cdecl *)(std::basic_ostream<_Elem,_Traits> &))'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program\microsoft visual studio 9.0\vc\include\ostream(176): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_ios<_Elem,_Traits> &(__cdecl *)(std::basic_ios<_Elem,_Traits> &))'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program\microsoft visual studio 9.0\vc\include\ostream(183): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::ios_base &(__cdecl *)(std::ios_base &))'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program\microsoft visual studio 9.0\vc\include\ostream(190): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::_Bool)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program\microsoft visual studio 9.0\vc\include\ostream(210): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(short)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program\microsoft visual studio 9.0\vc\include\ostream(243): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned short)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program\microsoft visual studio 9.0\vc\include\ostream(263): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(__w64 int)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program\microsoft visual studio 9.0\vc\include\ostream(288): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(__w64 unsigned int)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program\microsoft visual studio 9.0\vc\include\ostream(308): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(long)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program\microsoft visual studio 9.0\vc\include\ostream(328): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(__w64 unsigned long)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program\microsoft visual studio 9.0\vc\include\ostream(349): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(__int64)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program\microsoft visual studio 9.0\vc\include\ostream(369): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned __int64)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program\microsoft visual studio 9.0\vc\include\ostream(390): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(float)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program\microsoft visual studio 9.0\vc\include\ostream(410): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(double)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program\microsoft visual studio 9.0\vc\include\ostream(430): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(long double)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program\microsoft visual studio 9.0\vc\include\ostream(450): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(const void *)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program\microsoft visual studio 9.0\vc\include\ostream(470): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_streambuf<_Elem,_Traits> *)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
while trying to match the argument list '(std::ostream, std::string)'
Build log was saved at "file://c:\Andreas\Programmering\Cpp\ArrayTesting\ArrayTesting\Debug\BuildLog.htm"
ArrayTesting - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped
</char></char></char></char></char></char></char></char></char></char></char></char></char></char></char></char></char></char></char></std::char_traits></char></char></std::char_traits></char></char></std::char_traits></char></char></std::char_traits></char></char></std::char_traits></char></char></std::char_traits></char></char></char></char>
I'm using Visual C++ 2008.
/Joplinazz
|
|
|
|
|
Damn, only few errors would have suffice !!!
moreover, your lines are too long to fix the <pre> tag...
did you correctly included the header needed ?
#include <string>
#include <iostream>
also, try to use std::string::c_str() to print the string out:
cout << (a[3]).c_str();
|
|
|
|
|
Haha, yeah you're right..
Thanks a lot for your help, the headers were the problem.
I didn't use #include <string> - Strange error(to me, hehe).
/Joplinazz
|
|
|
|
|
Well, looks good to me.
I suppose you have included iostream. It doesn't show since you haven't used the small < and > wonders below the text input frame when you posted your message.
Joplinazz wrote: And one other thing; how can i create a string from several elements of this array?
Try this:
#include <sstream>
int main()
{
std::string Strings[] = { "a", "b", "c" };
std::ostringstream stm;
stm << Strings[2] << Strings[0] << Strings[1] << std::endl;
std::cout << stm.str().c_str();
} You'll get "cab" written to cout.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Thanks Roger, I managed to make it work this way:
myString = a[0] + a[1];
/Joplinazz
|
|
|
|
|
How do I create a UI thread capable of showing CDialog? I'm currently using AfxBeginThread for my working thread but also want to be able to display things like CDialog.DoModal from inside the worker thread. Do I have to make it a UI thread? How do I go about it?
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
|
The second version wants a subclassed CWinThread, but I'm not sure where exactly to place my code in it. May be in InitInstance. Any suggestions?
I already have the worker thread and the code for it, I need to know what to change to make showing modal CDialogs possible.
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
The second link shows common CWinThread overrides
and what those overrides should do.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Sorry, I didn't notice it. Thanks.
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
Hi.I'm using visual c++ 9.0.
I want to do something like this:
string name = get_name();
string filename = name+("text.dat");
ifstream infile_file;
infile_file.open(filename);
(code)
(...)
I'm doing something wrong... or I am missing something.
Here is the error:
error C2664: 'void std::basic_ifstream<_Elem,_Traits>::open(const wchar_t *,std::ios_base::openmode,int)' : cannot convert parameter 1 from 'std::string' to 'const wchar_t *'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Thanks.
"Failure is always an option."
|
|
|
|
|
this is because you're building your appblication in UNICODE most probably...
try removing the declaration of that macro and rebuild.
forget that. std::string::c_str() is the way to go
modified on Wednesday, September 3, 2008 11:05 AM
|
|
|
|
|
I did remove the declaration in progect properties.. but didn't work...
But thanks anyway for your help.
"Failure is always an option."
|
|
|
|
|
yeah, after reading David's Answer, I figured out my mistake...
|
|
|
|
|
FrankMookie wrote: infile_file.open(filename);
Try:
infile_file.open(filename.c_str());
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
it worked just fine withinfile_file.open(filename.c_str()); . Thanks alot!
"Failure is always an option."
|
|
|
|
|
Hey,
i've written a simple ActiveX-Control which shows a Dialog (CDialog) with some CEdit Controls. All works fine in TestContainer, but when I us the control for e.g. in Excel (2003, 2007) i can't write text to my edit controls. All text is shows on my worksheet.
Help me please...
|
|
|
|
|
Hello,
i need to get data from an Excel sheet, which is saved as xlsx file.
Is it possible to access a xlsx file over CDaoDatabase and CDaoRecordset like the old xls excel files?
Thanks,
Andy
|
|
|
|
|
Andy@ wrote: Is it possible to access a xlsx file over CDaoDatabase and CDaoRecordset like the old xls excel files?
If the xlsx file is an XML file then probably not.
Do you have a C++ or MFC question?
led mike
|
|
|
|
|
The code base i use is MFC, with a class that get the Data from the xls Excel format over the MFC classes CDaoDatabase and CDaoRecordset.
I wrote this some times ago. Now i need to handle the new format of xlsx files.
I thought that xlsx is always XML, but i´ve now opend the xlsx file with a hex editor and it seems to be a bin file.
I need a hint or a solution how i can get data from the xlsx file over MFC or Visual C++.
regards,
andy
|
|
|
|
|
Andy@ wrote: The code base i use is MFC, with a class that get the Data from the xls Excel format over the MFC classes CDaoDatabase and CDaoRecordset.
I wrote this some times ago. Now i need to handle the new format of xlsx files.
I don't know if DAO will work but here is some information about using OLEDB/ADO[^]
led mike
|
|
|
|
|