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);
int strSize = word_to_guess.size();

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().

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.