help on making int to string from function

This is a discussion on help on making int to string from function within the C++ Programming forums, part of the General Programming Boards category; hi, can someone give me a hints that how can i make int that called from the function and make ...

  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,672
    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.
    I used to be an adventurer like you... then I took an arrow to the knee.

  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
    Posts
    5,439
    >> 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:
    int main(void){srand(time(0));for(double l=rand(),l0=0,l00=0;;l0+=0.1){for(double l000=0;l000
    <1;l000+=.001,l+=((double)rand()/RAND_MAX)/0x64,l00+=((sin(l*0x8*atan(l0)*l000-(l0*0x8*atan
    (l)))*0.5)+0.5)){l00-=floor(l00);for(size_t l0000=0,l00000=(size_t)(0x50*(l00));l0000<l00000;++l0000
    )putchar(0x20);putchar(0x61+(int)((double)rand()/RAND_MAX*0x1a));putchar('\n');}}return 0;}

  5. #5
    Registered User
    Join Date
    Mar 2006
    Posts
    726
    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,041
    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, 04: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, 02:23 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21