I am trying to limit user input into alphabet only, then sort all the character in ascending order.
build messages error: no matching function for call to 'std::__cxx11::basic_string::basic_string(char&)'
This is my header
#include <iostream>
#include <string.h>
#include <conio.h>
#include <stdio.h>
#include <regex>
should i convert the char into string then convert back to char for my following code ?
string Sortstr (str[mlength]);
sort(Sortstr.begin(), Sortstr.end());
getting this 2 line error.
int mlength = 100;
int main() {
char str[mlength];
int length;
cout << "Please enter a c-string: ";
cin.getline(str,mlength,'\n');
regex pass1("^[a-zA-Z]+");
while(!regex_match(str,pass1)) {
cout<<"Error"<<endl;
cout << "Please enter a c-string: ";
cin.getline(str,mlength,'\n');
}
string Sortstr (str);
sort(str, str + strlen(str));
}
string Sortstr (str[mlength]);is undefined behavior, due to indexing the array out of bounds, not to mention, that it is non-standard C++ to use VLAs )variable length arrays) in the first place (mlengthis notconstexpr).chararray to begin with instead of astd::string?string Sortstr (str[mlength]);==>string Sortstr(str);. And you are using non-standard VLAs in C++. Avoid that, and just use astd::stringandstd::getlineproperly.