Hi there! I'm currently learning C++ in class and ran into a bit of a weird issue while working with strings. I've got two strings set up like this:
std::string str1 = "example";
std::string str2 = "example2";
I thought I could just assign str2 to str1 using:
str1 = str2;
However, my compiler throws an error saying "error: no viable overloaded '='" along with a message about a conversion from 'std::string' to 'const char*'. I was under the impression that both variables were the same type, so I'm confused. Any insights?
3 Answers
It looks like there might be an issue with the way you've set up your code. You mentioned getting an error that doesn't match the example you provided, which usually means something's not quite lining up. Could you share the exact lines of code where you're seeing this error? That could help pinpoint the issue.
From what you've described, everything should work fine with `std::string`. One possibility is that str1 could actually be a different type, like `char const*`. Just double-check that it's defined as `std::string` throughout to avoid any issues.
This error typically happens when str1 was declared as a `char const*` rather than `std::string`. It might be worth checking your code again to ensure that all your declarations are correct.

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically