Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 numbers in a line
Index -> Programming, C++ -> C++ Help
Goto page Previous  1, 2
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Null




PostPosted: Fri Nov 03, 2006 6:32 pm   Post subject: (No subject)

wtd, you know those std::string's should be passed in as const references...
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Fri Nov 03, 2006 7:16 pm   Post subject: (No subject)

Null wrote:
wtd, you know those std::string's should be passed in as const references...


Refresh my memory... which strings?
Null




PostPosted: Fri Nov 03, 2006 10:42 pm   Post subject: (No subject)

code:

#include <vector>
#include <string>
#include <sstream>

std::vector<int> read_all_numbers_from_string(std::string s)
{
   std::istringstream buffer(s);
   int temporary_integer;

   std::vector<int> output;

   while (true)
   {
      buffer >> temporary_integer;
     
      if (buffer.fail())
      {
         break;
      }
      else
      {
         output.push_back(temporary_integer);
      }
   }

   return output;
}
wtd




PostPosted: Fri Nov 03, 2006 10:54 pm   Post subject: (No subject)

Ah. I thought you were referring to my STL-exploiting code. Smile
md




PostPosted: Fri Nov 03, 2006 10:59 pm   Post subject: (No subject)

Null wrote:
wtd, you know those std::string's should be passed in as const references...


For all you know the data is stored as the same copy and is just a reference internally, the STL does not specify that it can't be Wink
wtd




PostPosted: Fri Nov 03, 2006 11:07 pm   Post subject: (No subject)

md wrote:
Null wrote:
wtd, you know those std::string's should be passed in as const references...


For all you know the data is stored as the same copy and is just a reference internally, the STL does not specify that it can't be Wink


Three words: Copy. On. Write. Smile
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 2 of 2  [ 21 Posts ]
Goto page Previous  1, 2
Jump to:   


Style:  
Search: