Thread: help on making int to string from function

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    141

    help on making int to string from function

    hi, can someone give me a hints that how can i make int that called from the function and make it to a string.

    for example. i have 3 function and there are integers.

    i want to make those into a function calledf myString.

    function 1 = 23, function 2 = 24, function 3 = 33

    and make it into one string called myString ...

    so when i cout<<myString; it will looks like
    myString[0] = 23
    myString[1] = 24
    myString[2] = 33

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Use a stringstream, here's a hint:
    Code:
    #include <sstream>
    #include <string>
    #include <iostream>
    
    ...
    
    int a = 23;
    int b = 24;
    int c = 33;
    
    // Create/initialize a stringstream
    std::stringstream sstr;
    sstr << a << " hello " << b << " world " << c;
    
    // Convert stringstream to a string
    std::string myString = sstr.str();
    
    // Output string
    std::cout << myString;
    Should output:
    Code:
    23 hello 24 world 33
    Now just apply that to what you have and what you need to see.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Jan 2006
    Posts
    141
    i have some problem for this when i input this to my work... i would like to discuss this privately .. can you provide ur email address please// would be appreciate

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    >> i would like to discuss this privately .. can you provide ur email address please// would be appreciate

    note: it's generally considered inappropriate (or at least bad taste) to request assistance via email.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  5. #5
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    What is your problem? Just spell it out here and you'll get more help than from private correspondance -- that's what forums are for.
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 05-13-2007, 08:55 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. Working with random like dice
    By SebastionV3 in forum C++ Programming
    Replies: 10
    Last Post: 05-26-2006, 09:16 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM