Hi all
on coding I met such a problem : which alike this code
#include<iostream>
#include<string>
using namespace std;
string& pstr2(const string& istr){
return istr
}
void pstr(const string& istr){
std::string::size_type sz_;
std::string::size_type sz_E;
sz_E = istr.length();
for (sz_ = 0; sz_ != sz_E ; sz_++){
cout << pstr2(istr.at(sz_)) << endl;
}
}
int main(int argc, char* argv[])
{
string str = " This is test sample";
pstr(str);
return 0;
}
you can not change pstr2() pstr1()'s parameter
$ g++ -o test1 test.cpp
test.cpp: In function a€?std::string& pstr2(const std::string&)a€?:
test.cpp:8: error: invalid initialization of reference of type
a€?std::string&a€? from expression of type a€?const
std::basic_string<char, std::char_traits<char>, std::allocator<chara€?
test.cpp:10: error: expected a€?;a€? before a€?}a€? token
test.cpp: In function a€?void pstr(const std::string&)a€?:
test.cpp:21: error: invalid conversion from a€?const chara€? to a€?const
char*a€?
test.cpp:21: error: initializing argument 1 of
a€?std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*,
const _Alloc&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc
= std::allocator<char>]a€?
how to solve it?
thank you very much
your
key9