Thank you, although I am getting an error:
error: variable 'std::wstringstream wss' has initializer but incomplete type
Did you #include <sstream>?
Oops... I did it now and it gives me another error:
error: cannot convert 'const wchar_t*' to 'LPCSTR {aka const char*}' for argument '2' to 'int MessageBoxA(HWND, LPCSTR, LPCSTR, UINT)'
My code:
#include <iostream>
#include <windows.h>
#include <sstream>
using namespace std;
int main()
{
float num1 = 10;
float num2 = 3;
float result = num1 / num2;
char fresult[0];
std::wstringstream wss(L"");
wss << fresult;
MessageBox(NULL, wss.str().c_str(), NULL, 0);
return 0;
}
Oh, use std::stringstream instead of std::wstringstream or use MessageBoxW() instead of MessageBox().
Last edited on
I used std::stringstream and it gives me one more error:
error: no matching function for call to 'std::basic_stringstream<char>::basic_stringstream(const wchar_t [1])'
std::wstringstream wss(L"");
The L"" is a wide-char string. For a normal char string remove the L.
Ok but it doesn't show 3.333..., it shows T"u or T"y etc. Is it possible for wss.str().c_str() to print 3.333...?
It should do... What is T"u and T"y?
Okay, this is the code:
#include <iostream>
#include <windows.h>
#include <sstream>
using namespace std;
int main()
{
float num1 = 10;
float num2 = 3;
float result = num1 / num2;
char fresult[0];
std::stringstream wss("");
wss << fresult;
MessageBox(NULL, wss.str().c_str(), NULL, 0);
return 0;
}
now, I want the message box to show: num1 / num2, but instead it shows me the letter T,
this symbol " and one random character while it should be showing the result of num1
divided by num2 which is 3.333... (10 / 3 = 3.333...)
wss << fresult;
should be
wss << result;
fresult contains junk because you didn't initialize it with anything.
Yes, thank you very much, that did it, thank you sir :)