|
-
Oct 24th, 2002, 10:18 AM
#1
Thread Starter
Addicted Member
string class: Using template constructor
I am using the string class in VC++ 6. I am attempting to use the template class constructor:
template <class InIt>
basic_string(InIt first, InIt last, const A& al = A());
However, when I attempt to construct a string using this I get errors about how there are no overloaded versions acceptable - or that it cannot convert from iterator to whatever type it feels like!
How can I use this templated class constructor?
Thanks
HD
-
Oct 24th, 2002, 12:22 PM
#2
Monday Morning Lunatic
You can only use basic_string for char or wchar_t, unfortunately...
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Oct 24th, 2002, 01:58 PM
#3
Thread Starter
Addicted Member
Hmm. I don't mean to question you, but the MSDN library documents a templated constructor that takes an initial point of an iterator, and a final point of an iterator (and the thing itself). It then 'should' give back a basic_string.
Have you heard of this before and have found that it doesn't work? I'd like to know of any information you have on the subject.
Although I've been using C and C++ for years now, I'm more of a C programmer and so the string class is a bit unfamiliar.
Thanks for any information
HD
-
Oct 24th, 2002, 02:42 PM
#4
Unfortunatly VC6 doesn't support member template functions:
MSDN:
In this implementation, if a translator does not support member template functions, the template:
Code:
template <class InIt>
basic_string(InIt first, InIt last, const A& al = A());
is replaced by:
Code:
basic_string(const_iterator first, const_iterator last,
const A& al = A());
The only solutions I can think of are:
1. Don't use VC6
2. first construct an empty string, then use std::copy(first,last,out)
-
Oct 25th, 2002, 11:32 AM
#5
Originally posted by twanvl
Unfortunatly VC6 doesn't support member template functions:
The only solutions I can think of are:
1. Don't use VC6
2. first construct an empty string, then use std::copy(first,last,out)
Unfortunatly the same restriction applies for std::copy.
If you ever choose to use a good compiler (gcc, VC++7, in that order ) you would do for example
list<wchar_t> ll;
ll.push_back(L'H');
ll.push_back(L'e');
ll.push_back(L'l');
ll.push_back(L'l');
ll.push_back(L'o');
basic_string<wchar_t> str(ll.begin(), ll.end());
wcout << str << endl;
which would output
Hello
You can only use containers that contain the same element type as the string, so if you use string ( = basic_string<char>) you can only copy from <char> containers. If you use wstring ( = basic_string<wchar_t>) you can only use <wchar_t> containers (like list<wchar_t>)
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Oct 25th, 2002, 12:35 PM
#6
Monday Morning Lunatic
/me has something going at the back of his mind that you can use iterator adapters to do a locale-conversion from wchar_t to char inline
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Oct 25th, 2002, 05:52 PM
#7
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Oct 26th, 2002, 06:43 AM
#8
Monday Morning Lunatic
If I ever get time 
So far most of my programming-related projects are on hold while I try and get my (real) work together
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|