Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8122417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:49:38+00:00 2026-06-06T05:49:38+00:00

I have a basic program that compares two strings : #include <string> #include <iostream>

  • 0

I have a basic program that compares two strings :

#include <string>
#include <iostream>

using namespace std;

int main (int argc, char *argv[]) {
  if(strcmp (argv[0],"./test") != 0) {
    cout << "not equal" << endl;
  } else {
    cout << "equal" << endl;
  }
  return 0;
}

it compiles with gcc but not with clang :

 > clang -o test test_clang.cpp 
test_clang.cpp:7:6: error: use of undeclared identifier 'strcmp'
  if(strcmp (argv[0],"./test") != 0) {
     ^
1 error generated.

Why doesn’t it compile with clang ?

EDIT: People are getting harsh on stack overflow, up to the point that I am hesitating to post a question. The question above has a simple answer, fine, but is it normal to down-vote questions (twice in the first minute!) because they have a simple, yet non obvious, answer ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T05:49:39+00:00Added an answer on June 6, 2026 at 5:49 am

    Use

    #include <string.h>
    

    or

    #include <cstring>
    

    instead of

    #include <string>
    

    The string header is for the std::string from C++. string.h is for C zero terminated char* strings. cstring is like string.h but for C++.

    The reason it worked with gcc is probably different warning/error level settings. It is possible to compile the code without #including the header and having the declaration of strcmp. The compiler will not be able to do type checking but the symbol still gets resolved by the linker.

    You can also avoid using strcmp completely and write

    #include <string>
    #include <iostream>
    
    int main (int argc, char *argv[]) {
      std::string command = argv[0];
    
      if( command != "./test" ) {
        std::cout << "not equal" << endl;
      } else {
        std::cout << "equal" << endl;
      }
      return 0;
    }
    

    Using a std::string on one side of the comparison will cause the “./test” string to be converted into a std::string as well and the comparison will be done by the == operator of the std::string class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have the following basic C++ program: #include <iostream> using namespace std; class
I currently have a basic chat program in c++ that uses WinSock2.h with UDP.
I have a program that downloads basic historical stock data from yahoo and puts
I have a program that I use to enter values into a database using
I have a real basic command-line program, in Objective-C, that searches for user inputed
I have a very basic Visual Basic Program that I created in Visual Studio
I have a basic ruby program, that listens on a port (53), receives the
I just restarted java for university and I have a pretty basic program that
Basically, I have to write a basic program that solves the n-queen problem, which
I have a fairly basic program that is intended to sort a list of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.