I'm currently writing a program and a problem has occurred. My problem is that I have multiple if-else statements, which does test some conditions and then I want multiple variables, which refers to a particular string, to be outputed in the same box.
My code is as following:
if(condition)
{
std::ostringstream os;
os << "some value" << x << "some other value" << std::endl;
std::string text = os.str();
CreateWindow(..., text.c_str(), ...)
} elseif(condition)
{
std::ostringstream os;
os << "some value" << x << "some other value" << std::endl;
std::string text = os.str();
CreateWindow(..., text.c_str(), ...)
} // etc.
if(new_condition)
{
std::ostringstream os;
os << "some value" << x << "some other value" << std::endl;
std::string text = os.str();
CreateWindow(..., text.c_str(), ...)
} elseif(new_condition)
{
std::ostringstream os;
os << "some value" << x << "some other value" << std::endl;
std::string text = os.str();
CreateWindow(..., text.c_str(), ...)
} // etc.
In this case it will create two different boxes. Everytime I try to get the value of one text, it wont allow me becuase the variable is inside the scope. How can I collect the text variables, so that it will output in one box (CreateWindow-function)?
Don't use Win32, you are just going to make your life harder. There are some good GUI libraries out there, I'd recommend Qt. Also Dev-C++ is really old and outdated, no idea why so many people end up using it. Do you check the date on articles and what not that recommend certain tools.
std::ostringstream os; //to be used in every if..else block
if(condition)
{
os << "some value" << x << "some other value" << std::endl;
} elseif(condition)
{
os << "some value" << x << "some other value" << std::endl;
} // etc.
if(new_condition)
{
os << "some value" << x << "some other value" << std::endl;
} elseif(new_condition)
{
os << "some value" << x << "some other value" << std::endl;
} // etc.
std::string text = os.str();
CreateWindow(..., text.c_str(), ...)
myesolar: Thanks for your advice. It is right that Bloodshed does not update it any more. However, a programmer, Orwell (Johan Mes) does update it. I use Dev-c++ because that was the tool I started with - old habits you know. Maybe I will on when the time comes.
booradley60: Thank you very much mate! That was exactly that solution I was looking for. Again, thank you very much!