Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ compile problem with strlen and strcpy

Tags:

c++

#include<iostream>
using namespace std;

int main()
{
    char a[5],b[5];
    cout<<strlen(a)<<endl;
    strcpy(a,b);
}

when I compile the code using g++ filename.cpp the code will be compiled with no issues but when my friends try to do it using dev-c++, they'll get errors!

based on cplusplus.com, I am the one who should get errors!!

so I am just wondering what's causing the difference here?

P.S: I have tried different versions of C++ using -std=c++98 throw -std=c++2a

like image 806
Sahashoo Avatar asked Feb 03 '26 22:02

Sahashoo


1 Answers

strlen and strcpy are declared in the <cstring> header. Some standard library implementations might include that in <iostream>, some might not. This explains why it may compile with some setups and not others.

like image 151
IlCapitano Avatar answered Feb 05 '26 11:02

IlCapitano



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!