problem with code after switching to visual studio 2005
-
just recently got visual studio 2005 and well to put a long story short it has been driving me crazy lol. but anyways i had to switch from using soem of the old libraries to usign the new ones and it has caused nothing but trouble. in my vc 6 i had a piece of code that would put any text i passed into a ostrstrea object(which in 2005 now is ostringstream) and it was stored into a char buffer which i would pass the buffer off to the setwindowtext function of a cedit control and it would display any text in the buffer but after a few changes to allow my program to compile the text will not display and i am not quite sure why. i have the code set up to work as it did in vc 6 but i am not sure what changes were made that now causes it to fail in vc 8, if someone could help me figure out what might be wrong i would greatly appreciate it.
-
just recently got visual studio 2005 and well to put a long story short it has been driving me crazy lol. but anyways i had to switch from using soem of the old libraries to usign the new ones and it has caused nothing but trouble. in my vc 6 i had a piece of code that would put any text i passed into a ostrstrea object(which in 2005 now is ostringstream) and it was stored into a char buffer which i would pass the buffer off to the setwindowtext function of a cedit control and it would display any text in the buffer but after a few changes to allow my program to compile the text will not display and i am not quite sure why. i have the code set up to work as it did in vc 6 but i am not sure what changes were made that now causes it to fail in vc 8, if someone could help me figure out what might be wrong i would greatly appreciate it.
swatgodjr wrote:
i passed into a ostrstrea object(which in 2005 now is ostringstream)
I suspect this means you used to use strstream.h. The standard headers you're now using in VC2005 were there in VC6, but it's taken this long for the headers that are not part of standard C++ to be removed from the Microsoft compiler.
swatgodjr wrote:
but i am not sure what changes were made
All the the changes made were to make the compiler more standards compliant, in other words, if your code had been legal C++, it would not have caused any problems.
swatgodjr wrote:
if someone could help me figure out what might be wrong i would greatly appreciate it.
I'm more than happy to help. Not much I can do without seeing the code :-)
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
swatgodjr wrote:
i passed into a ostrstrea object(which in 2005 now is ostringstream)
I suspect this means you used to use strstream.h. The standard headers you're now using in VC2005 were there in VC6, but it's taken this long for the headers that are not part of standard C++ to be removed from the Microsoft compiler.
swatgodjr wrote:
but i am not sure what changes were made
All the the changes made were to make the compiler more standards compliant, in other words, if your code had been legal C++, it would not have caused any problems.
swatgodjr wrote:
if someone could help me figure out what might be wrong i would greatly appreciate it.
I'm more than happy to help. Not much I can do without seeing the code :-)
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
ok not a problem, i been constantly looking for ways to redo the code correctly but not much luck yet well heres the code to one part of my program:
const int TEXT_SIZE = 5000; char szbuf[TEXT_SIZE]; std::ostringstream str(szbuf); void CHelpDialog::help_mes(char num[], bool cnt, char mess[]) { if(cnt == true) { str << " " << num << ". " << mess << "\r" << std::endl; } if(cnt == false) { str << " " << mess << "\r" << std::endl; } } BOOL CHelpDialog::OnInitDialog() { CEdit *pHelpText; pHelpText = (CEdit *) GetDlgItem(IDC_HELPTEXT); str.seekp(0); help_mes("1", true, "Everything entered in this program is case-sensitive so if"); help_mes("", false, "your program fails to load when you type in name of the plug"); help_mes("", false, "in to load, check if you spelled it correctly with the right"); help_mes("", false, "capitalization.\n"); help_mes("2", true, "If the program you enter fails to load, make sure you have the"); help_mes("", false, "required dll files needed for the program."); help_mes("3", true, "If there is any more bugs found than please contact me to let me"); help_mes("", false, "know. I can be reached at swatgod@gmail.com.\n"); pHelpText->SetWindowText(szbuf); memset(szbuf, 0, sizeof(szbuf)); return true; }
that is all the code that basically deals with the problem area, any advice is very much appreciated :). -
ok not a problem, i been constantly looking for ways to redo the code correctly but not much luck yet well heres the code to one part of my program:
const int TEXT_SIZE = 5000; char szbuf[TEXT_SIZE]; std::ostringstream str(szbuf); void CHelpDialog::help_mes(char num[], bool cnt, char mess[]) { if(cnt == true) { str << " " << num << ". " << mess << "\r" << std::endl; } if(cnt == false) { str << " " << mess << "\r" << std::endl; } } BOOL CHelpDialog::OnInitDialog() { CEdit *pHelpText; pHelpText = (CEdit *) GetDlgItem(IDC_HELPTEXT); str.seekp(0); help_mes("1", true, "Everything entered in this program is case-sensitive so if"); help_mes("", false, "your program fails to load when you type in name of the plug"); help_mes("", false, "in to load, check if you spelled it correctly with the right"); help_mes("", false, "capitalization.\n"); help_mes("2", true, "If the program you enter fails to load, make sure you have the"); help_mes("", false, "required dll files needed for the program."); help_mes("3", true, "If there is any more bugs found than please contact me to let me"); help_mes("", false, "know. I can be reached at swatgod@gmail.com.\n"); pHelpText->SetWindowText(szbuf); memset(szbuf, 0, sizeof(szbuf)); return true; }
that is all the code that basically deals with the problem area, any advice is very much appreciated :).I'd replace it all with the following: BOOL CHelpDialog::OnInitDialog() { std::ostringstream str(); str << "enter your text here, the helper function doesn't seem that useful to me"; CEdit *pHelpText; pHelpText = (CEdit *) GetDlgItem(IDC_HELPTEXT); pHelpText->SetWindowText(str.str().c_str()); return true; } Why are you putting \r AND std::endl ? If you must have the helper fumction, I'd use a conditional operator, as in str << " " << ((cnt) ? num : mess) << std::endl; Although as it stands you pass two char arrays each time, and each time use only one, which seems kind of redundant.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
I'd replace it all with the following: BOOL CHelpDialog::OnInitDialog() { std::ostringstream str(); str << "enter your text here, the helper function doesn't seem that useful to me"; CEdit *pHelpText; pHelpText = (CEdit *) GetDlgItem(IDC_HELPTEXT); pHelpText->SetWindowText(str.str().c_str()); return true; } Why are you putting \r AND std::endl ? If you must have the helper fumction, I'd use a conditional operator, as in str << " " << ((cnt) ? num : mess) << std::endl; Although as it stands you pass two char arrays each time, and each time use only one, which seems kind of redundant.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
umm i just noticed something rather interesting. your code works perfectly and yet when i made the small change that you had made i still get no text and i think now i understand why that is. but also i have a function like that since i once had this program being used in a console app and in that version separated a lot of my most common chunks of code into a separate dll that i used in multiple programs and just have not gotten around to redoing the same process in my gui apps. and i also use /r and endl because if i don't it will not terminate and drop other pieces of text to another line with how i was doing text in my cedit boxes in my program.
-
umm i just noticed something rather interesting. your code works perfectly and yet when i made the small change that you had made i still get no text and i think now i understand why that is. but also i have a function like that since i once had this program being used in a console app and in that version separated a lot of my most common chunks of code into a separate dll that i used in multiple programs and just have not gotten around to redoing the same process in my gui apps. and i also use /r and endl because if i don't it will not terminate and drop other pieces of text to another line with how i was doing text in my cedit boxes in my program.
OK, so your own code requires the \r and ignores somehow the \r\n being put in by std::endl ? Either way, your problem is solved then ?
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
OK, so your own code requires the \r and ignores somehow the \r\n being put in by std::endl ? Either way, your problem is solved then ?
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
no worries - just wanted to make sure we'd solved it :-)
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog