Text labels...

P

peter_k

Hi

I was programming a lot in C
When i wanted to make text label i was using something like:

#define MY_PROGRAM_RESULTS "Result of the program = %d\n"
printf(MY_PROGRAM_RESULTS, result);

But this method works only when i use stdio functions... Now i have
started using iostream cout<< and cin>> functions...

In what way should i store text labels (if i want to display few
variables in one line)?
 
M

Mike Wahler

peter_k said:
Hi

I was programming a lot in C
When i wanted to make text label i was using something like:

#define MY_PROGRAM_RESULTS "Result of the program = %d\n"
printf(MY_PROGRAM_RESULTS, result);

But this method works only when i use stdio functions... Now i have
started using iostream cout<< and cin>> functions...

In what way should i store text labels (if i want to display few
variables in one line)?

#include <iostream>
#include <sstream>
#include <string>

const std::string prog_result("Result of the program = ");

int main()
{
int i(42);
std::eek:stringstream oss;
oss << prog_result << i;

std::string text(oss.str());
std::cout << text << '\n'; // prints: Result of the program = 42
return 0;
}

-Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top