Why Visual Studio 2019 Enterprise version is not supported to the default formation of C++, I used Code-Blocks for a long time and still using it. Code Blocks was my first IDE to start with C++ and now for the graphical interface I use Visual Studio but when it comes to editing the source code, Visual Studio is not accepting many things that is accepted in Code-Blocks. A little example is declaring a string
in visual studio is not acceptable but it needs to be String
to work properly.
Maybe this is a Compiler Issue but I am not familiar with all Compilers, I used minGW in Codeblocks.
Asked
Active
Viewed 366 times
-3

Ted Lyngmo
- 93,841
- 5
- 60
- 108

Саша
- 837
- 4
- 12
-
3You must `#include
` and it must be `std::string` unless you are `using namespace std;` ([which is bad practice](https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice)). Please show a [mre]. – Lukas-T Jan 18 '21 at 12:21 -
2The standard library has class `std::string`, Arduino has it's own `String`, I don't of any other variations. – Yksisarvinen Jan 18 '21 at 12:21
-
Did you `#include
` and `using std::string`? – SimonC Jan 18 '21 at 12:21 -
Read [this C++ reference](https://en.cppreference.com/w/cpp) – Basile Starynkevitch Jan 18 '21 at 12:22
-
@SimonC Yes the string is included – Саша Jan 18 '21 at 12:22
-
4This is not C++ though. It's C++/CLI if I'm not mistaken. – Ted Lyngmo Jan 18 '21 at 12:23
-
@TedLyngmo I created an empty project c++/clr – Саша Jan 18 '21 at 12:25
-
2@Саша If you're targeting the CLR, you're most likely programming in C++/CLI, not C++, and from what I see in your picture it sure does look like it. (`System::Object^ sender` wouldn't even compile in C++) – Ted Lyngmo Jan 18 '21 at 12:26
-
@TedLyngmo it's mean the question should be closed? – Саша Jan 18 '21 at 12:36
-
1@Саша No, no, it's enough to put the correct tag on it (which I did) I think. – Ted Lyngmo Jan 18 '21 at 12:39
-
1@TedLyngmo I am not about the tag correction, but I think my question is totally incorrect, I must learn about C++/CLI and come back to VS – Саша Jan 18 '21 at 12:43
1 Answers
0
What you'll find is you're not including the string header, nor are you actually referencing the std::string object.
To import:
#include <string>
using std::string; // This is optional, but it saves you from having to type std::string all the time.

SimonC
- 1,547
- 1
- 19
- 43
-
2Actually, typing `std::string` in full makes much more readable code... – Basile Starynkevitch Jan 18 '21 at 12:23
-
-
@BasileStarynkevitch I beg to differ. I find it much less readable, as it adds no more information to the code. – SimonC Jan 18 '21 at 12:25
-
@Саша But you're not `using` the string anywhere, as far as I can tell. If your file is empty, paste the code here so we can all read it. – SimonC Jan 18 '21 at 12:26
-
@SimonC The project is empty but it has 500 lines of code generated by VS in it's .h file in which I am editing the code – Саша Jan 18 '21 at 12:46
-
1