Here's my code, also I don't want to change "
this symbol.
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str = "-/"0123456789";
cout << str;
return 0;
}
Here's my code, also I don't want to change "
this symbol.
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str = "-/"0123456789";
cout << str;
return 0;
}
You can either use an escape sequence for the quotation mark, i.e. replace it with ", or use a raw string literal. In a raw string literal, you enclose the string using R"( at the beginning, and )" at the end.
To illustrate:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str1 = "-/\"0123456789"; //Escape sequence \"
string str2 = R"(-/"0123456789)"; //Raw string literal
cout << str1 << endl;
cout << str2 << endl;
return 0;
}
You need to escape with \
not /
.
string str = "-\"0123456789";
-"0123456789
If you wanted to include the /
then you can use
string str = "-/\"0123456789";
-/"0123456789
In C++11 you can use a raw string
string str = R"(-"0123456789)"
-"0123456789
or
string str = R"(-/"0123456789)"
-/"0123456789