I'm trying to convert my basic C code to C++ using the C++ syntax instead of C syntax, if that makes sense. However, I have a problem. I don't know how to use strlen()
in C++. In preprocessing, I have #include <iostream>
#include <string>
and using namespace std;
. When I try to compile, it gave the following error messages:
error: use of undeclared identifier 'strlen'
int n = strlen(MessagetEnc);
and
error: use of undeclared identifier 'strlen'
for (int i = 0; i < strlen(MessagetEnc); i++)
Also, using #include <cstring>
doesn't seem to fix the problem.
This is the code:
#include <iostream>
#include <string>
using namespace std;
int main ()
{
int EncCode;
std::cout << "Encryption code: " << std::endl;
std::cin >> EncCode;
string MessagetEnc;
std::cout << "Message to Encrypt:";
std::cin >> MessagetEnc;
std::cout << "Output: " << endl;
int n = strlen(MessagetEnc);
for (int i = 0; i < strlen(MessagetEnc); i++)
{
std::cout <<"Encrypted message" << MessagetEnc[i];
}
}
I know C++ isn't beginner-friendly, I just wanted to try it after reading a few articles, as I plan to fully learn it after I leave the "beginner stage."
Edit: std::
is there because I tried getting rid of using namespace std;
as a way to debug.