when i want to convert it to char,give me segment fault error
                  
                  
                  std::string a;
                  
                  
                  char *b;
                  
                  
                  cin>>a;
                  
                  
                  str(b,a.c_string());
                  
                  
                  it because want to copy to pointer instead of place that it point?
                  
                  
                  or something else?
                  
                  
                  how can i do it?
                  
                  
                
You need to specify the size of char array first
std:: string s; s = "Some String"; int n = s.length(); char char_array[n + 1]; strcpy(char_array, s.c_str());
Обсуждают сегодня