|
Im assuming that m_lstrComputers is a std::list < std::string >
In that case, your error is that std::list< T > does not have an operator[], which is logical since it does not support random access iterators. You will have to walk your way to idx either from .begin() or .end().
#include < string >
#include < iostream >
#include < list >
using namespace std;
class c
{
list< string > l_;
public:
c()
{
l_.push_back("test");
l_.push_back("me");
}
string operator [] (unsigned int i)
{
list< string >::iterator it = l_.begin();
while (i-- != 0)
it++;
return *it;
}
};
int main()
{
c c;
cout << c[0] << endl;
return 0;
}
---
“Our solar system is Jupiter and a bunch of junk” - Charley Lineweaver 2002
|
|
|
|
|
Jonas Larsson wrote:
You will have to walk your way to idx either from .begin() or .end().
Of course, this is true. However, instead of writing his own loop for that, he can simply use advance function template. Something like:
string operator [] (unsigned int i)
{
list<string>::iterator it = l_.begin();
advance(it, i);
return *it;
}
|
|
|
|
|
Even better!
I havent seen that function template before (Im only halfway through my copy of Josuttis book). Thanks for the tip!
---
“Our solar system is Jupiter and a bunch of junk” - Charley Lineweaver 2002
|
|
|
|
|
Hii Everybody,
I have written a ATL COM Component and I am calling through ASP.NET Web Application. But after after logout and setting object of component to null, It is not releasing component at all. I have to stop process aspnet_wp.exe for recompilation of component.
Any suggestion by you all experts that how can I release component after logout of web Application?
Please help me...
Regards
Anuj Mishra
Software Engineer
|
|
|
|
|
Marshal.ReleaseComObject
To quote MSDN: "This method is used to explicitly control the lifetime of a COM object used from managed code. You should use this method to free the underlying COM object that holds references to resources in a timely manner or when objects must be freed in a specific order."
|
|
|
|
|
It has nothing to do with CTreeViewCtrl. Look for bugs in your program.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Thank you for the reply.
I found bug in my source code.
-Freehawk
|
|
|
|
|
Hi list,
I need to compile the following code with gcc:
//test.cpp
#include <iostream>
int main()
{
std::cout << "Hello World";
return 0;
}
But trying "gcc test.cpp" fails miserably, because it cannot find some symbols:
ld: Undefined symbols:
std::ios_base::Init::Init[in-charge]()
std::ios_base::Init::~Init [in-charge]()
std::cout
std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
Can anybody please help me to find what is really missing?
TIA
Theofilactos Botaniaths
|
|
|
|
|
You probably need to tell gcc (via the command line) to search and link with a particular library file. Someone who knows what library file will probably be along soon.
This is a link-time, rather than a compile-time error. Sorry I can't be more help.
Steve S
|
|
|
|
|
Hi Steve,
Steve S wrote:
You probably need to tell gcc (via the command line) to search and link with a particular library file. Someone who knows what library file will probably be along soon.
This is a link-time, rather than a compile-time error. Sorry I can't be more help.
Yes that seams to be the case...
I've tried some (obvious) libraries but no luck
Thanks,
Theofilactos Botaniaths
|
|
|
|
|
Theofilactos Botaniaths wrote:
But trying "gcc test.cpp" fails miserably, because it cannot find some symbols
Try g++ test.cpp instead.
|
|
|
|
|
Hi Nemanja,
Nemanja Trifunovic wrote:
Try g++ test.cpp instead.
Yes it works!
Thanks so much!
Theofilactos Botaniaths
|
|
|
|
|
g++ is basically an alias for gcc --some-magic-c++-library-inclusions
--
Unser Tanz ist so wild! Ein neuer böser Tanz.
Alle gegen Alle!
|
|
|
|
|
Hi Jörgen,
Jörgen Sigvardsson wrote:
g++ is basically an alias for gcc --some-magic-c++-library-inclusions
Well, I was wondering about that as well, but I was too shy to ask...
This seems to be a great list.
Thanks!
Best Regards
Theofilactos Botaniaths
|
|
|
|
|
Hello everyone:
I have a WTL project for GUI and some MFC dlls.
Now there is a problem. In the interface of MFC dlls there are some "CString" data type, If not change these "CString" data types, can I transfer some strings from WTL project to MFS dlls? Is there other ways to relealize it?
Thank you.
-Freehawk
|
|
|
|
|
|
Thank you for the fast reply.
In my WTL project,
CString a = "1234"; // a is WTL string
// call mfc dll function
SendDataToMFCDll(a);
In my MFC dll
void SendDataToMFCDll(CString a)
{
// a is MFC string
...
}
is it right?
-Freehawk
|
|
|
|
|
|
Thank you.
What you said is as the following?
In my WTL project,
CString a = "1234"; // a is WTL string
// call mfc dll function
SendDataToMFCDll((LPCTSTR)a);
In my MFC dll
void SendDataToMFCDll(CString a)
{
// a is MFC string
...
}
-Freehawk
|
|
|
|
|
Please help me I lost my night sleep. Tell in simple code.
From my VB client I am passing simple string "Siddharth", to a win32 dll function GetUserName(DATATYPE)(if DAtatype is BSTR or wstring tell me how to convert it into string in dll function declaration). My program should run in 98 as well as NT. I am trying lot of examples but they all are for long. When I convert it to string nothing works out.
VB client
Dim x as string
x = "String"
GetStringFromVb(wstring *)
end
Win32
GetStringFromVb(wstring*)
{
vector<string> MyString;
MyString.push_back(wstring);
{
//..Lot of string manipulation
}
}
One more issue. in the win32 DLL.h if I declare stl parameter, it is not accepted by the compiler.
|
|
|
|
|
hi sidharth,
when u r passing string in vc++ they are accepted in BSTR format. so u have to first change into CString and then to char* to use it as a string.
function used to perform this is
#include<cstring.h>
CString CString_str = _T("");
if (BSTR_str != NULL) // To be sure that input string is valid...
{
CString s;
LPSTR p = s.GetBuffer(::SysStringLen(BSTR_str) + 1);
BOOL UsedDefaultChar;
::WideCharToMultiByte(CP_ACP, 0, BSTR_str, -1,
p, ::SysStringLen(BSTR_str)+1,
NULL, &UsedDefaultChar);
if (UsedDefaultChar)
// BSTR_str contains an ANSI string
CString_str = (LPCTSTR)BSTR_str;
else
// BSTR_str contains an UNICODE string
CString_str = (LPCWSTR)BSTR_str;
}
char *temp = LPSTR(CString_str);
further if u have to include MFC support at the time of creating new ATL project
I hope it will help u.
Ritu
|
|
|
|
|
Thanx a lot buddy. That was a breather. I will try and get back.But I am not using MFC. and if I include <iostream> it will create conflict. Any way let me try first.
|
|
|
|
|
Can i serialize an object with WTL like doing with MFC
vi
|
|
|
|
|
|
"the value of ESP was not properly saved across a function call." i got this error dialog while compiling a MFC client. the MFC client is empty except for a ATL control added to the UI. the ATL control is empty too. Just as it was 1st created by the wizard.
any idea what's wrong?
|
|
|
|