Home > front end >  error message of no suitable user-defined conversion
error message of no suitable user-defined conversion

Time:12-23

 #include <iostream>
 #include <string.h>
 #include <strings.h>
 #include <algorithm>
 #include <bits/stdc  .h>
 #include <string>
 #include <algorithm>
 #include <iterator>
 #include <list>

 int main(){

char buffer[32] = {0};
std::string temp;
std::string apend;
//memset(buffer, '\0', sizeof(buffer));

std::cout << "Text in: \n";
  fgets(buffer, 32, stdin);
        for(int i = 0; i < strlen(buffer);   i){
            for(int j = 0; j < strlen(buffer);   j){
                if(buffer[i] == ' '){
                    buffer[i] = buffer[i 1];
                }
            }
        }

    for(int i=0; i < strlen(buffer);   i){
        std::cout << buffer[i]; 
        temp  = buffer[i];
    }

    reverse(temp.begin(), temp.end());
    std::cout << temp << std::endl;

    std::cout << "Enter a new string: \n" << std::endl;
    std::cin >> apend;
    temp.append(apend);

    for(auto i = temp.begin(); i != temp.end();   i){
        std::cout << *i <<" ";
    }
    std::vector<std::string>::iterator ptr1 = temp.begin();

there is a error message saying no suitable user-defined conversion..., at 'ptr1 = temp.begin(), and i just can't deal with this problem. Can someone help take a look of my practice? Thanks!

return -1;

 }

CodePudding user response:

You need to use the correct type which is decltype(temp)::iterator ptr1 = temp.begin(); - that is, ptr1 is a std::string::iterator, not a std::vector<std::string>::iterator. So for your snippet to compile, change

std::vector<std::string>::iterator ptr1 = temp.begin();

to

auto ptr1 = temp.begin(); // ptr1 is a std::string::iterator
  •  Tags:  
  • c
  • Related