gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 16:32:55 27 4
gpt4 key购买 nike

初步说明:string_algo 与 std::wstring 一起工作得很好,当然我可以(并且确实)将 CString 对象转换为 std::wstring首先,如果以及何时我需要来自 string_algo 的算法。如果我可以直接放入 CString 对象,那就太好了——与现有代码的集成会容易得多!

我想做的事情:

CString in = ...;
const CString out = boost::replace_last_copy(in, L"SEARCH", L"REPLACE");

作为suggested here我尝试另外包含 boost/range/mfc.hpp 以获得 Boost.Range adapted to MFC . (虽然我不太明白 this header,但它似乎对 CString 没有任何作用,只对集合类起作用。)

使用 Visual Studio 2005 boost 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 *'

最佳答案

尝试将 CString 替换为 CStringW,以防 CString 映射到 CStringA

确切的错误代码如何,在标题的哪一行?您可以尝试替换本地代码中的相同错误吗?

关于visual-c++ - 如何将 MFC CString 与 boost 字符串算法库一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17467312/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com