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 7178179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:52:09+00:00 2026-05-28T16:52:09+00:00

I am using a std::vector to store some strings, later I try to std::find

  • 0

I am using a std::vector to store some strings, later I try to std::find them but passing through strdup, as shown in the sample code, It does not work, std::find returns last, which means it did not find the string, but I can see that it is there, as I access it through the std::vector::at function, and it is displayed correctly. What is the problem?

#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <stdint.h>
#include <string.h>

int main()
{
    std::vector<char*> signal_list;
    std::vector<char*>::iterator it;
    char *temp;
    char *temp2;

    signal_list.push_back("DDF_LTEsyn__CALLER");
    signal_list.push_back("DDF_LTEsyn__FFT_ctrl");
    signal_list.push_back("DDF_LTEsyn__IFFT_ctrl");
    signal_list.push_back("DDF_LTEsyn__ae_ctrl");
    signal_list.push_back("DDF_LTEsyn__cwp_ctrl");
    signal_list.push_back("DDF_LTEsyn__decision_ctrl");
    signal_list.push_back("DDF_LTEsyn__ovelap_ctrl");
    signal_list.push_back("DDF_LTEsyn__pilots_ctrl");
    signal_list.push_back("DDF_LTEsyn__pre_ctrl");
    signal_list.push_back("DDF_LTEsyn__rep_ctrl");

    temp2 = strdup(signal_list.at(3));

    printf("There is %s at position %d\n",temp2, 3);

    it = find(signal_list.begin(), signal_list.end(), temp2);

    printf("i found %s at position %d ",temp2, it - signal_list.begin());

}
  • 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-05-28T16:52:09+00:00Added an answer on May 28, 2026 at 4:52 pm

    You’re comparing pointer addresses, not strings. You should use a std::vector<std::string> or use std::find_if() and pass it a predicate that can compare char pointers.

    Here is how you could do the second of those:

    bool compare(const char *str1, const char *str2)
    {
        return strcmp(str1, str2) == 0;
    }
    
    it = std::find_if(signal_list.begin(), signal_list.end(), std::bind2nd(std::ptr_fun(compare), tmp2));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using a vector of strings in order to store some data in
I'm using the 'using' declaration in C++ to add std::string and std::vector to the
When using the std::for_each, class A; vector<A*> VectorOfAPointers; std::for_each(VectorOfAPointers.begin(), VectorOfAPointers.end(), std::mem_fun(&A::foo)); If we have
#include <iostream> using namespace std; // This first class contains a vector and a
#include <iostream> #include <vector> using namespace std; int main() { vector< vector<int> > dp(50000,
#include <iostream> #include <vector> using namespace std; int main(void) { int i, s, g;
Consider the following code: #include <iostream> #include <memory> #include <vector> using namespace std; struct
#include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; int main(void) {
I need to find an element position in an std::vector to use it for
Say want to store the following: typedef std::function<void(int)> MyFunctionDecl; ..in a collection: typedef std::vector<MyFunctionDecl>

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.