Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,970 questions

51,912 answers

573 users

How to remove the first word from string in C++

2 Answers

0 votes
#include <iostream>
#include <string>

using std::cout;
using std::endl;
using std::string;

int main()
{
	string s = "c++ c c# java php";

	s = s.substr(s.find_first_of(" \t") + 1);

	cout << s << endl;

	return 0;
}


/*
run:

c c# java php

*/

 



answered Apr 19, 2018 by avibootz
0 votes
#include <iostream>
#include <string>

using std::cout;
using std::endl;
using std::string;

// Function to remove the first word (up to first space or tab)
string TrimFirstWord(const string& input) {
    size_t pos = input.find_first_of(" \t");
    
    if (pos != string::npos)
        return input.substr(pos + 1);
        
    return input; // return original if no space or tab found
}

int main()
{
    string s = "c++ c c# java php";

    s = TrimFirstWord(s);

    cout << s << endl;

    return 0;
}


/*
run:

c c# java php

*/

 



answered Sep 25, 2025 by avibootz

Related questions

1 answer 58 views
1 answer 66 views
2 answers 158 views
1 answer 88 views
1 answer 68 views
1 answer 100 views
...