dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: char array to istream

Hybrid View

  1. #1
    Join Date
    Apr 2009
    Posts
    2

    char array to istream

    hello,

    I am using a static library(NTL), and it has a function I need to use, problem is it accepts inputs by cin, while I need to pass it by command line arguments.

    here is the code

    #include <NTL/ZZXFactoring.h>

    NTL_CLIENT

    int main()
    {
    ZZX f;

    cin >> f;

    vec_pair_ZZX_long factors;
    ZZ c;

    factor(c, factors, f);

    cout << c << "\n";
    cout << factors << "\n";
    }

    as it can be seen, it takes f as an istream object (and f should be inputted as: [9 10 3] )
    but I want to pass f with command line arguments. like: executable [9 10 3] )
    int main(int argc, char *argv[])
    {
    ZZX f ;
    int *temp;
    int k [argc];
    temp=k;
    for(int i=1; i<argc;i++)
    {
    f=atoi(argv[i]);
    *temp=atoi(argv[i]);
    temp++;
    }
    //f =atoi(argv[1]);

    vec_pair_ZZX_long factors;
    ZZ c;
    factor(c, factors, f);
    cout << c << "\n";
    cout << factors << "\n";
    }

    How can I do that without changing library quickest way?

  2. #2
    Join Date
    Jan 2008
    Location
    California, USA
    Posts
    822

    Re: char array to istream

    Hello!
    using code tags will help you get a better response!
    All you have to do is copy and paste the code in my signature,
    compile it, run it, enter the name of the source file, and viola!
    the formatted contents will be in z.txt file with all the coloring! C++ style!
    And just copy it back when you post it next time!
    Please try it, it's less than 30 lines, Comeau compliant, highly coustomizable, and free!
    ...unless we already have a bbcode for that...do we? (other than [php])

    Code:
    #include <NTL/ZZXFactoring.h> 
    
    NTL_CLIENT 
    
    int main() 
    { 
    ZZX f; 
    
    cin >> f; 
    
    vec_pair_ZZX_long factors; 
    ZZ c; 
    
    factor(c, factors, f); 
    
    cout << c << "\n"; 
    cout << factors << "\n"; 
    } 
    
    
    int main(int argc, char *argv[]) 
    { 
    ZZX f ; 
    int *temp; 
    int k [argc]; 
    temp=k; 
    for(int i=1; i<argc;i++) 
    { 
    f=atoi(argv[i]); 
    *temp=atoi(argv[i]); 
    temp++; 
    } 
    //f =atoi(argv[1]); 
    
    vec_pair_ZZX_long factors; 
    ZZ c; 
    factor(c, factors, f); 
    cout << c << "\n"; 
    cout << factors << "\n"; 
    }
    Last edited by potatoCode; April 14th, 2009 at 12:10 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)