I
I
igoodmood2016-04-24 15:47:10
Programming
igoodmood, 2016-04-24 15:47:10

What is the error: the expression must have a class type?

I want to implement a program that transfers some of the elements to another array, then some of the elements are deleted in it, thereby forming, as it were, two substrings. But there was an error: in the line "str.erase(u);
" writes an error: "The expression must have a class type". How to fix this error? Thank you in advance.
Here is the code itself:

#include "stdafx.h"
#include <iostream>
#include "string"
#define MAX 50
using namespace std;
int main()
{
  setlocale (LC_ALL, "Russian");
  char s1[MAX],s2[MAX],str[50];
  int i=0,u=0,j=0;
  cout << "Введите строку:";
  cin >> str;
  i = strlen(str);
  j = i / 2;
  u = i - j;
  strncpy (s1, str, j );
  s1[j] = '\0';
  cout << s1 << endl;
  str.erase(u);
  cout << s2 << endl; 
  system("pause");
  return 0;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2016-04-24
@zagayevskiy

You are calling the erase method on a char array. In C++, arrays don't have methods at all. Look towards std::string. This is a class and it has this method:
www.cplusplus.com/reference/string/string/erase

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question