Text labels...

Discussion in 'C++' started by peter_k, Nov 25, 2005.

  1. peter_k

    peter_k Guest

    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)?
    peter_k, Nov 25, 2005
    #1
    1. Advertising

  2. peter_k

    Mike Wahler Guest

    "peter_k" <> wrote in message
    news:...
    > 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
    Mike Wahler, Nov 25, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tony collier
    Replies:
    2
    Views:
    366
    tony collier
    Jan 12, 2004
  2. Neo
    Replies:
    0
    Views:
    336
  3. Bad Starter
    Replies:
    0
    Views:
    353
    Bad Starter
    Jul 18, 2006
  4. Keithb
    Replies:
    0
    Views:
    2,897
    Keithb
    Nov 4, 2006
  5. Replies:
    2
    Views:
    389
    Thomas Heller
    Nov 29, 2006
Loading...

Share This Page