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

  • Home
  • SEARCH
  • 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 704465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:56:41+00:00 2026-05-14T03:56:41+00:00

This is a very simple question and I feel stupid for asking it, but

  • 0

This is a very simple question and I feel stupid for asking it, but I am pressed for time and I need to figure it out 🙂

I just need to know how to make a string that contains text and other variables. For instance in Java I can just do this:

String someString;

for(int i = 0; i>10; i++){

someString = ("this text has printed " + i + " times"); //how do I create this line in C++?

System.out.println(someString);

i++;

}

EDIT 4:

Ok, Rahul G’s answer below works pretty good, and the program compiles and ok, but when I run it instead of getting the string I want for the file name, I get a bunch of numbers. For instance: << "frame " << i << " .jpg" creates: “013679000.jpg” instead of “frame 0.jpg” like I want. Any thoughts?

for(int i = 0; frames; i++)
{  
  frame = cvQueryFrame(capture); 
  std::string s = static_cast<std::ostringstream &>(std::ostringstream() << argv[1] <<  i << " .jpg").str(); 
  cvSaveImage(s.c_str(), frame);
} 
  • 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-05-14T03:56:42+00:00Added an answer on May 14, 2026 at 3:56 am

    Java:

    int i = 5;
    double d = 2.23606798;
    String s = "Square root of "+i+" is "+d;
    

    C++:

    int i = 5;
    double d = 2.23606798;
    std::ostringstream oss;
    oss << "Square root of " << i << " is " << d;
    std::string s = oss.str();
    // If you need C style string...
    char const *s0 = s.c_str();
    

    Please note that the std::ostringstream class resides in <sstream> header.

    Edit:

    Your code (corrected):

    for(int i = 0; frames; i++) { 
      frame = cvQueryFrame(capture);
      std::ostringstream oss;
      oss << "frame " << i << " .jpg";
      cvSaveImage(oss.str().c_str(), frame);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this is a darn simple question, but I'm very used to using
I think this may be a very simple question, but I am only just
I feel like the answer to this question is probably very simple, but I'm
This is a very simple question with a simple answer, but it is not
This must be a very simple question, but I don't seem to be able
Warning - I am very new to NHibernate. I know this question seems simple
I'm sure this is a very stupid question but I can't find the answer,
I feel like this is a simple question, but I am still relatively new
I feel somewhat foolish asking such a simple question, but I can't seem to
I think this is a very simple question, but when I copy an image

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.