473,386 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Map with string key and wstring[] value

Hi!

I'd like to have a map with string keys, and wstring[] (arrays) values
in c++.

I thought map<string, wstring[]would work out, but it doesn't (at
least I think so).

Additionally I'd like to know what's the easiest way to populate such
a map.

Would - mymap["somekey"] = {L"My Unicode value one", L"My other
unicode value"}; - work?

Many thanks in advance.
Jun 27 '08 #1
6 3443
campesr wrote:
I'd like to have a map with string keys, and wstring[] (arrays) values
in c++.
You can't do that. The stored value has to satisfy certain requirements
(be copy-constructible and assignable), and arrays don't.
I thought map<string, wstring[]would work out, but it doesn't (at
least I think so).

Additionally I'd like to know what's the easiest way to populate such
a map.

Would - mymap["somekey"] = {L"My Unicode value one", L"My other
unicode value"}; - work?
No. The closest you can get to what you want is to have

std::map<string, std::vector<wstring

..

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 27 '08 #2
On 23 Mai, 17:25, Victor Bazarov <v.Abaza...@comAcast.netwrote:
campesr wrote:
I'd like to have a map with string keys, and wstring[] (arrays) values
in c++.

You can't do that. The stored value has to satisfy certain requirements
(be copy-constructible and assignable), and arrays don't.
I thought map<string, wstring[]would work out, but it doesn't (at
least I think so).
Additionally I'd like to know what's the easiest way to populate such
a map.
Would - mymap["somekey"] = {L"My Unicode value one", L"My other
unicode value"}; - work?

No. The closest you can get to what you want is to have

std::map<string, std::vector<wstring

.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Thanks.
Jun 27 '08 #3
Hi!

Victor Bazarov schrieb:
No. The closest you can get to what you want is to have

std::map<string, std::vector<wstring
I suggest to try a deque because it offers better or equally good time
complexity for all operations:

map<string, deque<wstring

:)

Regards,
Frank
Jun 27 '08 #4
Frank Birbacher wrote:
Hi!

Victor Bazarov schrieb:
>No. The closest you can get to what you want is to have

std::map<string, std::vector<wstring

I suggest to try a deque because it offers better or equally good time
complexity for all operations:

map<string, deque<wstring

:)
Except that std::deque does not have the same property that may be
important to the OP -- the data are not stored contiguously. The
storage of a vector can be easily used where an array can be used (like
passing it to a third-party library that expects an array via a pointer
to the first element).

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 27 '08 #5
Hi!

Victor Bazarov schrieb:
Except that std::deque does not have the same property that may be
important to the OP -- the data are not stored contiguously.
Yes, right. I should have mentioned it. I'm sorry.

Frank
Jun 27 '08 #6
On 23 Mai, 22:33, Frank Birbacher <bloodymir.c...@gmx.netwrote:
Hi!

Victor Bazarov schrieb:
Except that std::deque does not have the same property that may be
important to the OP -- the data are not stored contiguously.

Yes, right. I should have mentioned it. I'm sorry.

Frank
OK. Many thanks to all of you.
Jun 27 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: vsgdp | last post by:
Hi, Is there a unicode equivalent to std::string?
3
by: edgekaos | last post by:
Is method 2 valid? Method 1: wstring input = L"STRING"; wstring output = input; transform(output.begin(), output.end(), output.begin(), towupper); Method 2: wstring input = L"STRING";...
6
by: gerg | last post by:
How would one convert a wstring to a string? This is what I have so far: bool copyto(std::string& l,std::wstring& r) { bool ret = false; size_t i = 0; const size_t n = r.length()+1;
19
by: SteveB | last post by:
Hi I'm having major problems writing a function that converts a long value into a wide string !!! I'm more than likely going round in circles and not seeing the wood for the trees now but am...
14
by: =?Utf-8?B?Sm9hY2hpbQ==?= | last post by:
I have seen the following function to convert from a System::String^ to a const wchar_t*. I would like to get a LPCTSTR and AFAIK LPCTSTR is equal to const wchar_t*. Then it should all work right?...
10
by: v4vijayakumar | last post by:
1. why the following program is not working as expected? #include <iostream> using namespace std; int main() { string t("test"); wcout << (wchar_t *) t.c_str() << endl; wcout << t.c_str()...
1
by: v4vijayakumar | last post by:
1. Why the following program is not working as expected? #include <iostream> using namespace std; int main() { string t("test"); wcout << (wchar_t *) t.c_str() << endl; wcout << t.c_str()...
6
by: frohlinger | last post by:
Hi, I need to perform some numeric calculations on a numeric float value, that is received as wstring. I would like to perform a check before converting the wstring to float, checking that indeed...
2
by: Saeed Amrollahi | last post by:
Dear All Hi I usually use the following function for built-in types to std::string conversion: // convert a type (typically built-in type) to std::string template<class T> inline std::string...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.