How would you implement a substr() function that extracts a sub string from a given string?



How would you implement a substr() function that extracts a sub string from a given string?..

Answer / Bhudev Singh

In C++, you can use the std::string::substr() function to obtain a substring. Here's an example: `std::string s = "hello world"; std::string substr = s.substr(6);`, which will extract the substring starting from the 7th character (index 6) to the end.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C++ General Interview Questions

How do you link a C++ program to C functions?

4 Answers  


What are the two types of comments?

1 Answers  


Mention the storage classes in c++.

1 Answers  


What is exception handling? Does c++ support exception handling?

1 Answers  


What is atoi in c++?

1 Answers  


what are Operators and explain with an example?

1 Answers  


What do you mean by function overriding & function overloading in c++?

1 Answers  


what is software cycle? What is a mission critical system ? What is the important aspect of a real-time system ? Explain the difference between microkernel and macro kernel. Give an example of microkernel.Why paging is used ? Which is the best page replacement algo and Why ? What is software life cycle ? How much time is spent usually in each phases and why Which one do U want to work if selected in Honeywell ? Which are the different types of testing ? What is a distributed system ? Some questions about CSP. Which languages do U know ? What are the differences between Pascal and C. questions from Compiler construction and Lisp. Which are the different computer architecture? What is the requirement in MIMD ? What is the difference between RISC and CISC processors ? Difference between loosely coupled and tightly coupled systems ? What is an open system?

1 Answers   Honeywell,


What are the advantages and disadvantages of using inline and const?

2 Answers   Polaris, TCS, Zimmer Biomet,


When is the destructor called?

1 Answers  


What is the difference between public, private, protected inheritance?

12 Answers   Wipro,


Problem 5: Hero's Formula is A method for calculating the area of a triangle when you know the lengths of all three sides. Let a, b, c be the lengths of the sides of a triangle. The area is given by:A= pp-ap-b(p-c) | wherep= a+b+c2 | | Write a C-language code to calculate area of triangle using above method. Take the three lengths of the triangle from the user and display the area that your program calculates.

0 Answers   Maxobiz,


Categories