Trying to find the string length,of word_to_guess,wont work,any suggestions???

#include <iostream>
#include <cstdlib>
#include <string>


using namespace std;

int main()


{
    int num;
    int size;
    int num_guess;
    string word_to_guess; 
    string words [10] = {"john","paul", etc}
    char exit = 'y';
    char guess;
    
    
          srand((unsigned)time(NULL));
          num = rand() % 9 + 0;
          
       
          
          word_to_guess = words[num];
          size = strlen(word_to_guess);

I know this is a bit of a "me too" post, but I thought I should clarify daviddoria's response.

strlen() only works with C-style strings (null-terminated arrays of chars). Since you are working with C++ std::strings you can not use it as you have. You need to use the member function std::string::size() instead. The function is called as stringName.size().

Edited 6 Years Ago by Fbody: n/a

This question has already been answered. Start a new discussion instead.