vector of strings for instdead of cout?

This is a discussion on vector of strings for instdead of cout? within the C++ Programming forums, part of the General Programming Boards category; Hi, I need a vector of strings to store the 1154 strings output of the following code? what is the ...

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    4

    Unhappy vector of strings for instdead of cout?

    Hi,
    I need a vector of strings to store the 1154 strings output of the following code?
    what is the best way of doing that? any idea?
    Thanks
    Hash-mobtadi

    Code:
    #include <iostream>
    #include<iomanip>
    #include <string>
    #include <sstream>
    using std::string;
    using namespace std;
    
    int main (){
        for (int i=0; i< 10; i++){
           
             for (int j=0; j< 10; j++){
             
                  for (int t=0; t< 10; t++){
               
                       for (int l=0; l< 10; l++){
                 
                 if ( (i*1000+ j*100 + t*10 + l) > 1154) break;
                
                
                 
                         cout<<"M0"<<i<<j<<t<<l<<endl;
                           }
                       }
                  }
             }
    system("pause");
      return 0;
    }

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Stringstreams are pretty similar to cout, but they send the output into a string and not to console.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    The just call str() on the stringstream and send that to push_back to add to the vector.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 04-29-2009, 10:13 AM
  2. oper overloading || Distances vs. Strings
    By xion in forum C++ Programming
    Replies: 3
    Last Post: 05-27-2004, 05:23 PM
  3. strings strings strings str..
    By Linette in forum C++ Programming
    Replies: 1
    Last Post: 02-17-2002, 01:12 PM
  4. c-style string vs. c++-style strings
    By Mbrio in forum C++ Programming
    Replies: 3
    Last Post: 02-10-2002, 11:26 AM
  5. strings
    By rc7j in forum C++ Programming
    Replies: 1
    Last Post: 11-14-2001, 12:47 PM

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