Click here to Skip to main content
15,911,711 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: progid Pin
User 2155974-Sep-08 23:11
User 2155974-Sep-08 23:11 
GeneralRe: progid Pin
George_George4-Sep-08 23:26
George_George4-Sep-08 23:26 
GeneralRe: progid Pin
User 2155974-Sep-08 23:44
User 2155974-Sep-08 23:44 
GeneralRe: progid Pin
George_George4-Sep-08 23:55
George_George4-Sep-08 23:55 
GeneralRe: progid [modified] Pin
User 2155975-Sep-08 0:03
User 2155975-Sep-08 0:03 
GeneralRe: progid Pin
George_George5-Sep-08 0:50
George_George5-Sep-08 0:50 
GeneralRe: progid Pin
User 2155975-Sep-08 0:55
User 2155975-Sep-08 0:55 
GeneralRe: progid Pin
George_George5-Sep-08 1:06
George_George5-Sep-08 1:06 
GeneralRe: progid Pin
User 2155975-Sep-08 1:24
User 2155975-Sep-08 1:24 
GeneralRe: progid Pin
George_George5-Sep-08 1:43
George_George5-Sep-08 1:43 
Questionproblem in reading data from com port Pin
manju23reddy4-Sep-08 20:22
manju23reddy4-Sep-08 20:22 
QuestionRe: problem in reading data from com port Pin
Roger Stoltz4-Sep-08 22:19
Roger Stoltz4-Sep-08 22:19 
AnswerRe: problem in reading data from com port Pin
manju23reddy5-Sep-08 8:05
manju23reddy5-Sep-08 8:05 
AnswerRe: problem in reading data from com port Pin
Roger Stoltz7-Sep-08 22:43
Roger Stoltz7-Sep-08 22:43 
Questionstring trim and toupper/tolower Pin
George_George4-Sep-08 19:47
George_George4-Sep-08 19:47 
AnswerRe: string trim and toupper/tolower Pin
Nibu babu thomas4-Sep-08 19:59
Nibu babu thomas4-Sep-08 19:59 
GeneralRe: string trim and toupper/tolower Pin
George_George4-Sep-08 20:04
George_George4-Sep-08 20:04 
GeneralRe: string trim and toupper/tolower Pin
Nibu babu thomas4-Sep-08 21:03
Nibu babu thomas4-Sep-08 21:03 
GeneralRe: string trim and toupper/tolower Pin
George_George4-Sep-08 21:40
George_George4-Sep-08 21:40 
GeneralRe: string trim and toupper/tolower Pin
Nibu babu thomas4-Sep-08 21:48
Nibu babu thomas4-Sep-08 21:48 
GeneralRe: string trim and toupper/tolower Pin
George_George4-Sep-08 21:58
George_George4-Sep-08 21:58 
GeneralRe: string trim and toupper/tolower Pin
Nibu babu thomas4-Sep-08 22:19
Nibu babu thomas4-Sep-08 22:19 
George_George wrote:
1.

No document which describes all possible exceptions may be thrown by a specific STL function, like string.substr?

2.

"the files exception and stdexcept" -- yes, but for a specific STL function like string.substr, how do you check all possible exceptions may be thrown by looking at the file? Smile


I am not sure where you can find them, but here is a more secure version of Trim.

void Trim( const std::string& StrToTrim, std::string& TrimmedString )
{
   // Find first non whitespace char in StrToTrim
   std::string::size_type First = StrToTrim.find_first_not_of( ' ' );
   // Check whether something went wrong?
   if( First == std::string::npos )
   {
      First = 0;
   }

   // Find last non whitespace char from StrToTrim
   std::string::size_type Last = StrToTrim.find_last_not_of( ' ' );
   // If something didn't go wrong, Last will be recomputed to get real length of substring
   if( Last != std::string::npos )
   {
      Last = ( Last + 1 ) - First;
   }

   // Copy such a string to TrimmedString
   TrimmedString = StrToTrim.substr( First, Last );
}


Earlier function will throw an out_of_range exception if we gave a string like " " for trimming. This one doesn't. Wink | ;)


Nibu babu thomas
Microsoft MVP for VC++


Code must be written to be read, not by the compiler, but by another human being.

Programming Blog: http://nibuthomas.wordpress.com

GeneralRe: string trim and toupper/tolower Pin
George_George4-Sep-08 22:47
George_George4-Sep-08 22:47 
AnswerRe: string trim and toupper/tolower Pin
Naveen4-Sep-08 20:10
Naveen4-Sep-08 20:10 
GeneralRe: string trim and toupper/tolower Pin
George_George4-Sep-08 20:11
George_George4-Sep-08 20:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.