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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:54:42+00:00 2026-06-08T03:54:42+00:00

Possible Duplicate: Reaching a specific word in a string I asked a very similar

  • 0

Possible Duplicate:
Reaching a specific word in a string

I asked a very similar question but apparently I asked it wrong. The question is that I need to reach the 3rd word in a string in C++ and the string is like this:

word1\tword2\tword3\tword4\tword5\tword6

word2 can have spaces inside.

I tried to read the string character by character but I found it inefficient. I tried code

std::istringstream str(array[i]); 
str >> temp >> temp >> word; 
array2[i] = word; 

and it didn’t work because of the spaces inside word2.

Can you tell me how I can do that?

  • 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-08T03:54:44+00:00Added an answer on June 8, 2026 at 3:54 am

    The most straightforward way:

    #include <iostream>
    int main()
    {
        //input string:
        std::string str = "w o r d 1\tw o r d2\tword3\tword4";
        int wordStartPosition = 0;//The start of each word in the string
    
        for( int i = 0; i < 2; i++ )//looking for the third one (start counting from 0)
            wordStartPosition = str.find_first_of( '\t', wordStartPosition + 1 );
    
        //Getting where our word ends:
        int wordEndPosition = str.find_first_of( '\t', wordStartPosition + 1 );
        //Getting the desired word and printing:
        std::string result =  str.substr( wordStartPosition + 1, str.length() - wordEndPosition - 1 );
        std::cout << result;
    }
    

    output:

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

Sidebar

Related Questions

Possible Duplicate: Yield In VB.NET In C#, when writing a function that returns an
Possible Duplicate: regex for URL including query string I have a text or message.
Possible Duplicate: Why is String.Concat not optimized to StringBuilder.Append? One day I was ranting
Possible Duplicate: Turning on camera flash LED in Android? I need to turn on
Possible Duplicate: std::string and its automatic memory resizing I am just curious, how are
Possible Duplicate: What is the fastest XML parser in PHP? I still need to
Possible Duplicate: Matlab gives wrong answer Can anyone explain to me why the following
Possible Duplicate: In Vim: How do I delete a word and go into insert
Possible Duplicate: how to use foursquare API in android application? This is a question
Possible Duplicate: git - removing a file from source control (but not from the

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.