-2

I want to replace a set of strings between << >> delimiters.

For example say

int age= 25; string name= "MYNAME"; string test = My age is << your age >> and my name is << your name >>. 

Output should be

My age is 25 and my name is MYNAME. 

What is the best method to do this is c++ ?

3

2 Answers 2

1

try this

#include <iostream> #include <string> int main () { std::string str ("My age is << your age >> and my name is << your name >>."); std::string str2 ("<< your age >>"); std::string str3 ("<< your name >>"); str.replace(str.find(str2),str2.length()," 22 "); str.replace(str.find(str3),str3.length()," Nooh "); std::cout << str << '\n'; return 0; } 
Sign up to request clarification or add additional context in comments.

Comments

-1

Im not sure I understand the question, but if its what I think it is, try

string test = "My age is " + age + " and my name is " + name + "."; 

If you are bent on using << and >>, you can do

cout << "My age is " << age << " and my name is " << name << "." << endl; 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.