Problem with GUI text boxes

Hello Cplusplus,

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
if(condition)
{
    std::ostringstream os;
    os << "some value" << x << "some other value" << std::endl;
    std::string text = os.str();

    CreateWindow(..., text.c_str(), ...)

} else if(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(), ...)

} else if(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)?

A note: I use Dev-C++ and my project is win32.

I hope that anyone can help me!

Thank you!
closed account (10X9216C)
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.
Expand the scope of the variable that collects the text, and create the window at this outer scope, as well:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
std::ostringstream os; //to be used in every if..else block

if(condition)
{
    os << "some value" << x << "some other value" << std::endl;
} else if(condition)
{
    os << "some value" << x << "some other value" << std::endl;
} // etc.

if(new_condition)
{
    os << "some value" << x << "some other value" << std::endl;
} else if(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!
Topic archived. No new replies allowed.