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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:51:00+00:00 2026-06-11T12:51:00+00:00

Lets say that we have a specific string: string a[]={ab,cd,ef} and we want a

  • 0

Lets say that we have a specific string:

string a[]={"ab","cd","ef"}

and we want a specific string when we input first character of the string:
for example:

input: c
output: "cd"

what i was thinking is that:

so let’s say we assign char x for the input value.
and then using the loop to go through the list, but i’m stuck of how char x is going to stop the loop and printing the specific string.

other question is how its going to be different to find a letter thats inside the string. for example inputing: d and output: “cd”

  • 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-11T12:51:02+00:00Added an answer on June 11, 2026 at 12:51 pm

    I will answer both of your questions (even though you should keep it to one question per “question”).

    To stop a loop you use the break statement.

    To find a character (or a string) in a string you use the std::string::find function.

    Now combining them:

    #include <string>
    #include <iostream>
    #include <algorithm>
    
    int main()
    {
        std::string a[] = { "ab", "cd", "ef", "ce" };
    
        char x;
        std::cout << "Enter a letter: ";
        std::cin >> x;
    
        // If you want to stop as soon as you find a string with the letter
        // you have to loop manually
        std::cout << "\nFind first string containing letter:\n";
        for (std::string s : a)
        {
            if (s.find(x) != std::string::npos)
            {
                std::cout << "Letter '" << x << "' found in string \"" << s << "\"\n";
                break;  // Stop the loop
            }
        }
    
        // If you want to print all strings containing the letter you can
        // use the `std::for_each` function
        std::cout << "\nFind all strings containing letter:\n";
        std::for_each(std::begin(a), std:end(a), [x](const std::string &s) {
               if (s.find(x) != std::string::npos)
                   std::cout << "Letter '" << x << "' found in string \"" << s << "\"\n";
            });
    }
    

    Note: The above code contains two features from the “new” C++11 standard: Range-based for-loops; And lambda functions.

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

Sidebar

Related Questions

Lets say that you have a following simple application: <form action=helloServlet method=post> Give name:<input
Lets say that I have an executable and when it is started I want
Lets say that I have an array that I want to convert to a
Lets say that i have 2 pages: index.php and service.php index.php sends an http-post
Lets say that i have a duration of time e.g., 10 minutes . I
Lets say that you have a business object whose current state implies that there
Lets say that I have only DHT (distributed hash table) implemented (in Python), and
Lets say that I have the following code: public class Shelter<A extends Animal, B
Lets say that i have the following array : float QuadVertices[4 * 2]; float
Lets say that I have one component which is doing something with Workbook object

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.