Click here to Skip to main content
16,004,887 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i using "gdiplus" library and i have a problem, i want to use string variable inside this variable, i don't know how to call it because i new at this library.

My program is just taking the image.bmp path inside a variable.

C++
string username()
{
    char username[UNLEN + 1];
    DWORD username_len = UNLEN + 1;
    GetUserName(username, &username_len);
    string pcuser = username;
    return pcuser;
}

int main()
{
    Gdiplus::Bitmap bmp("C:\\Users\\" + username() + "\\Documents\\Visual Studio Things\\image.bmp");
    return 0;
}

So, how can i use username() inside a Bitmap ?

What I have tried:

I tried to use .c_str with the username() but this is not working. any suggestions ? I'm getting this error

Error (active) E0289 no instance of constructor "Gdiplus::Bitmap::Bitmap" matches the argument list argument types are: (std::basic_string, std::allocator>)
Posted
Updated 10-Nov-19 20:16pm

[EDIT]
Correction, you're using the wrong terminology.

You don't "use a string in a bitmap". You're trying to use the return value from your username function in a path.

This has nothing to with a Bitmap. This is just string manipulation in C.

For now, simplify what you're doing. Forget the Bitmap junk and stop trying to use as few lines of code as possible. DO NOT DIRECTLY USE THE RETURN VALUE OF A METHOD CALL IN A COMPOUND STATEMENT. You're just making it harder on yourself to debug your code.

Read: https://www.codingame.com/playgrounds/14213/how-to-play-with-strings-in-c/string-concatenation[^]
 
Share this answer
 
v3
Comments
[no name] 10-Nov-19 11:26am    
Stupid f***ing answer, but thanks! i already success it.
Dave Kreskowiak 10-Nov-19 11:32am    
Even dumber question. Your subject line didn't match what you started the question with, not did it match the code you posted.
[no name] 10-Nov-19 11:34am    
Yes it is, but you cannot give a simple answer, you are always need to be different and give some stupid functions. (":
Dave Kreskowiak 10-Nov-19 11:36am    
You either read up on how to do string manipulation in C and FIGURE IT OUT FOR YOURSELF, or you are forever going to be dependent on other people to write your code for you.

String manipulation is a set of basic techniques that you MUST LEARN if you want any chance at all of succeeding at writing code.
[no name] 10-Nov-19 11:37am    
Of course i need that, but not to this specific problem, the answer it just to use wstring instead of string. that's all.
Very simple code in your main function:
C++
string name = username();
Gdiplus::Bitmap bmp("C:\\Users\\" + name + "\\Documents\\Visual Studio Things\\image.bmp");
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900