mardi 24 janvier 2023

Error when I attempt to split a string into individual characters

I read online you can "separate" a string and well it doesn't work. Of course the code is more complex than this but I only have troubles in this part.As I said below as well, the exact error is:

no viable conversion from 'std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator >::value_type' (aka 'char') to 'std::__ndk1::string' (aka 'basic_string<char, char_traits, allocator >')

So I have no idea how to proceed, but my code is as follows:

#include<iostream>

using namespace std;

int main()

{

string word;

cin>>word;

string word1 = word [0];

string word2 = word[1];

string word3 = word[2];

string word4 = word[3];

return 0;

}

The exact error I get is:

no viable conversion from 'std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator >::value_type' (aka 'char') to 'std::__ndk1::string' (aka 'basic_string<char, char_traits, allocator >')

Aucun commentaire:

Enregistrer un commentaire