Visual c++ 如何将MFC CString与boost字符串算法库一起使用

Visual c++ 如何将MFC CString与boost字符串算法库一起使用,visual-c++,boost,mfc,boost-range,string-algorithm,Visual C++,Boost,Mfc,Boost Range,String Algorithm,初步说明:string_algo与std::wstring配合很好,当然,如果需要string_algo的算法,我可以(并且确实)首先将CString对象转换为std::wstring。不过,如果我能直接插入CString对象,那就太好了——与现有代码的集成会容易得多 我想做的是: CString in = ...; const CString out = boost::replace_last_copy(in, L"SEARCH", L"REPLACE"); 当我试图另外包括boost/ra

初步说明:string_algo与
std::wstring
配合很好,当然,如果需要string_algo的算法,我可以(并且确实)首先将CString对象转换为std::wstring。不过,如果我能直接插入CString对象,那就太好了——与现有代码的集成会容易得多

我想做的是:

CString in = ...;
const CString out = boost::replace_last_copy(in, L"SEARCH", L"REPLACE");
当我试图另外包括
boost/range/mfc.hpp
时。(虽然我不太了解它,但它似乎对CString没有任何作用,只对集合类有作用。)

使用VisualStudio2005增强1.44.0

测试代码如下所示:

#include "stdafx.h"
#include <iostream>
#include <boost/range/mfc.hpp>
#include <boost/algorithm/string.hpp>

void f(CString const& input) {
    CString out = boost::replace_last_copy(input, L"FROM", L"TO");
    std::wcout << out << "\n";
}
1>c:\programme\boost_library-1_44_0\boost\algorithm\string\detail\find_format_store.hpp(77) : error C2039: 'type' : is not a member of 'boost::range_const_iterator<C>'
1>        with
1>        [
1>            C=const CString
1>        ]
1>        c:\programme\boost_library-1_44_0\boost\algorithm\string\detail\find_format.hpp(139) : see reference to function template instantiation 'bool boost::algorithm::detail::check_find_result<const InputT,const FindResultT>(InputT &,FindResultT &)' being compiled
1>        with
1>        [
1>            InputT=CString,
1>            FindResultT=boost::iterator_range<const wchar_t *>
1>        ]
1>        c:\programme\boost_library-1_44_0\boost\algorithm\string\find_format.hpp(113) : see reference to function template instantiation 'InputT boost::algorithm::detail::find_format_copy_impl<SequenceT,FormatterT,boost::iterator_range<IteratorT>>(const InputT &,FormatterT,const FindResultT &)' being compiled
1>        with
1>        [
1>            InputT=CString,
1>            SequenceT=CString,
1>            FormatterT=boost::algorithm::detail::const_formatF<boost::iterator_range<const wchar_t *>>,
1>            IteratorT=const wchar_t *,
1>            FindResultT=boost::iterator_range<const wchar_t *>
1>        ]
1>        c:\programme\boost_library-1_44_0\boost\algorithm\string\replace.hpp(314) : see reference to function template instantiation 'SequenceT boost::algorithm::find_format_copy<SequenceT,boost::algorithm::detail::last_finderF<SearchIteratorT,PredicateT>,boost::algorithm::detail::const_formatF<RangeT>>(const SequenceT &,FinderT,FormatterT)' being compiled
1>        with
1>        [
1>            SequenceT=CString,
1>            SearchIteratorT=const wchar_t *,
1>            PredicateT=boost::algorithm::is_equal,
1>            RangeT=boost::iterator_range<const wchar_t *>,
1>            FinderT=boost::algorithm::detail::last_finderF<const wchar_t *,boost::algorithm::is_equal>,
1>            FormatterT=boost::algorithm::detail::const_formatF<boost::iterator_range<const wchar_t *>>
1>        ]
1>        ....\mytest.cpp(10) : see reference to function template instantiation 'SequenceT boost::algorithm::replace_last_copy<CString,const wchar_t[5],const wchar_t[3]>(const SequenceT &,Range1T (&),Range2T (&))' being compiled
1>        with
1>        [
1>            SequenceT=CString,
1>            Range1T=const wchar_t [5],
1>            Range2T=const wchar_t [3]
1>        ]
1>c:\programme\boost_library-1_44_0\boost\algorithm\string\detail\find_format_store.hpp(78) : error C3203: 'type' : unspecialized class template can't be used as a template argument for template parameter 'IteratorT', expected a real type
1>c:\programme\boost_library-1_44_0\boost\algorithm\string\detail\find_format.hpp(121) : error C2780: 'void boost::algorithm::detail::insert(InputT &,InputT::iterator,const InsertT &)' : expects 3 arguments - 4 provided
1>        c:\programme\boost_library-1_44_0\boost\algorithm\string\detail\sequence.hpp(39) : see declaration of 'boost::algorithm::detail::insert'
1>        c:\programme\boost_library-1_44_0\boost\algorithm\string\detail\find_format.hpp(144) : see reference to function template instantiation 'InputT boost::algorithm::detail::find_format_copy_impl2<InputT,FormatterT,FindResultT,boost::iterator_range<IteratorT>>(const InputT &,FormatterT,const FindResultT &,const FormatResultT &)' being compiled
1>        with
1>        [
1>            InputT=CString,
1>            FormatterT=boost::algorithm::detail::const_formatF<boost::iterator_range<const wchar_t *>>,
1>            FindResultT=boost::iterator_range<const wchar_t *>,
1>            IteratorT=const wchar_t *,
1>            FormatResultT=boost::iterator_range<const wchar_t *>
1>        ]
1>c:\programme\boost_library-1_44_0\boost\algorithm\string\detail\find_format.hpp(121) : error C2893: Failed to specialize function template 'void boost::algorithm::detail::insert(InputT &,InputT::iterator,ForwardIteratorT,ForwardIteratorT)'
1>        With the following template arguments:
1>        'CString'
1>        'const wchar_t *'
1>c:\programme\boost_library-1_44_0\boost\algorithm\string\detail\find_format.hpp(123) : error C2893: Failed to specialize function template 'void boost::algorithm::detail::insert(InputT &,InputT::iterator,const InsertT &)'
1>        With the following template arguments:
1>        'CString'
1>        'boost::iterator_range<IteratorT>'
1>        with
1>        [
1>            IteratorT=const wchar_t *
1>        ]
1>c:\programme\boost_library-1_44_0\boost\algorithm\string\detail\find_format.hpp(123) : error C2780: 'void boost::algorithm::detail::insert(InputT &,InputT::iterator,ForwardIteratorT,ForwardIteratorT)' : expects 4 arguments - 3 provided
1>        c:\programme\boost_library-1_44_0\boost\algorithm\string\detail\sequence.hpp(29) : see declaration of 'boost::algorithm::detail::insert'
1>c:\programme\boost_library-1_44_0\boost\algorithm\string\detail\find_format.hpp(125) : error C2780: 'void boost::algorithm::detail::insert(InputT &,InputT::iterator,const InsertT &)' : expects 3 arguments - 4 provided
1>        c:\programme\boost_library-1_44_0\boost\algorithm\string\detail\sequence.hpp(39) : see declaration of 'boost::algorithm::detail::insert'
1>c:\programme\boost_library-1_44_0\boost\algorithm\string\detail\find_format.hpp(125) : error C2893: Failed to specialize function template 'void boost::algorithm::detail::insert(InputT &,InputT::iterator,ForwardIteratorT,ForwardIteratorT)'
1>        With the following template arguments:
1>        'CString'
1>        'const wchar_t *'
#包括“stdafx.h”
#包括
#包括
#包括
无效f(CString常量和输入){
CString out=boost::替换最后一份拷贝(输入,L“FROM”,L“TO”);
std::wcout with
1>        [
1> C=常数CString
1>        ]
1> c:\program\boost\u library-1\u 44\u 0\boost\algorithm\string\detail\find\u format.hpp(139):请参阅正在编译的函数模板实例化“bool boost::algorithm::detail::check\u find\u result(input&,FindResultT&)”的参考
1> 与
1>        [
1> input=CString,
1> FindResult=boost::迭代器范围
1>        ]
1> c:\program\boost\u library-1\u 44\u 0\boost\algorithm\string\find\u format.hpp(113):请参阅正在编译的函数模板实例化“input boost::algorithm::detail::find\u format\u copy\u impl(const input&,FormatterT,const FindResultT&)”
1> 与
1>        [
1> input=CString,
1> SequenceT=CString,
1> FormatterT=boost::algorithm::detail::const\u formatF,
1> 迭代器端口=常量wchar\u t*,
1> FindResult=boost::迭代器范围
1>        ]
1> c:\Program\boost\u library-1\u 44\u 0\boost\algorithm\string\replace.hpp(314):请参阅正在编译的函数模板实例化“SequenceT boost::algorithm::find\u format\u copy(const SequenceT&,FinderT,FormatterT)”的参考
1> 与
1>        [
1> SequenceT=CString,
1> SearchIteratorT=const wchar\u t*,
1> 谓词集=boost::算法::等于,
1> RangeT=boost::迭代器\u范围,
1> FinderT=boost::algorithm::detail::last_finderF,
1> FormatterT=boost::算法::细节::常量
1>        ]
1> ..\mytest.cpp(10):请参阅正在编译的函数模板实例化“SequenceT boost::algorithm::replace_last_copy(const SequenceT&,Range1T(&),Range2T(&))”的参考
1> 与
1>        [
1> SequenceT=CString,
1> Range1T=常数wchar\u t[5],
1> Range2T=常数wchar\u t[3]
1>        ]
1> c:\Program\boost\u library-1\u 44\u 0\boost\algorithm\string\detail\find\u format\u store.hpp(78):错误C3203:“类型”:非专用类模板不能用作模板参数“IteratorT”的模板参数,应为实类型
1> c:\program\boost\u library-1\u 44\u 0\boost\algorithm\string\detail\find\u format.hpp(121):错误C2780:“void boost::algorithm::detail::insert(input&,input::iterator,const InsertT&”):需要3个参数-提供4个参数
1> c:\program\boost\u library-1\u 44\u 0\boost\algorithm\string\detail\sequence.hpp(39):参见“boost::algorithm::detail::insert”的声明
1> c:\program\boost\u library-1\u 44\u 0\boost\algorithm\string\detail\find\u format.hpp(144):请参阅正在编译的函数模板实例化“input boost::algorithm::detail::find\u format\u copy\u impl2(const input&,formatter,const findresult&,const formatresult&)”
1> 与
1>        [
1> input=CString,
1> FormatterT=boost::algorithm::detail::const\u formatF,
1> FindResult=boost::迭代器范围,
1> 迭代器端口=常量wchar\u t*,
1> FormatResultT=boost::迭代器范围
1>        ]
1> c:\Program\boost\u library-1\u 44\u 0\boost\algorithm\string\detail\find\u format.hpp(121):错误C2893:未能专门化函数模板“void boost::algorithm::detail::insert(输入和输入::迭代器,ForwardIterator,ForwardIterator)”
1> 使用以下模板参数:
1> “CString”
1> “const wchar\u t*”
1> c:\Program\boost\u library-1\u 44\u 0\boost\algorithm\string\detail\find\u format.hpp(123):错误C2893:未能专门化函数模板“void boost::algorithm::detail::insert(输入和,输入::迭代器,常量插入和)”
1> 使用以下模板参数:
1> “CString”
1> 'boost::迭代器范围'
1> 与
1>        [
1> 迭代器端口=常量wchar\t*
1>        ]
1> c:\program\boost\u library-1\u 44\u 0\boost\algorithm\string\detail\find\u format.hpp(123):错误C2780:'void boost::algorithm::detail::insert(input&,input::iterator,forwarditerator,forwarditerator)':需要4个参数-提供3个参数
1> c:\program\boost\u library-1\u 44\u 0\boost\algorithm\string\detail\sequence.hpp(29):参见“boost::algorithm::detail::insert”的声明
1> c:\Program\boost\u library-1\u 44\u 0\boost\algorithm\string\detail\find\u format.hpp(125):错误C2780:“void boost::algorithm::detail::insert(Input&,Input::iterator,const InsertT&”):需要3个参数-提供4个参数
1> c:\program\boost\u library-1\u 44\u 0\boost\algorithm\string\detail\sequence.hpp(39):参见“boost::algorithm::detail::insert”的声明
1> c:\Program\boost\u library-1\u 44\u 0\boost\algorithm\string\detail\find\u format.hpp(125):错误C2893:未能专门化函数模板“void boost::algorithm::detail::insert(输入和输入::迭代器,ForwardIterator,ForwardIterator)”
1> 使用以下模板参数:
1> “CString”
1> “const wchar\u t*”

如果
CString
映射到
CStringA
,请尝试将
CString
替换为
CStringW

确切的错误代码是什么,在标题的哪一行?你能试着替换本地co中的相同错误吗