我试图在Windows上为应用程序创建横幅。
// C Libraries:
#include <string>
#include <iostream>
#include <algorithm>
// Namespaces:
using namespace std;
const char *BANNER[] = R"BANNER(
.-') _ .-')
( OO) ) ( OO ).
,--. ,--. / '._ ,-.-') ,--. ,-.-') (_)---\_)
| | | | |'--...__)| |OO) | |.-') | |OO)/ _ |
| | | .-')'--. .--'| | \ | | OO ) | | \\ :` `.
| |_|( OO ) | | | |(_/ | |`-' | | |(_/ '..`''.)
| | | `-' / | | ,| |_.'(| '---.',| |_.'.-._) \
(' '-'(_.-' | | (_| | | |(_| | \ /
`-----' `--' `--' `------' `--' `-----')BANNER";
char* getCmdOption(char ** begin, char ** end, const std::string & option)
{
char ** itr = find(begin, end, option);
if (itr != end && ++itr != end)
{
return *itr;
}
return 0;
}
bool cmdOptionExists(char** begin, char** end, const std::string& option)
{
return find(begin, end, option) != end;
}
int main(int argc, char * argv[])
{
printf("%s\n", BANNER);
if(cmdOptionExists(argv, argv+argc, "-h"))
{
cout << "Help Menu";
}
if (cmdOptionExists(argv, argv + argc, "-a"))
{
cout << "Adobe";
}
return 0;
}
我已经阅读了多个线程和多个网站,您可以使用语法R"(<string here>)";
或R"BANNER(<string here>)BANNER";
来创建多行字符串。但是,当我编译此代码时,我收到以下错误:
utilis.cpp(9) : error C2001: newline in constant
utilis.cpp(9) : error C2065: 'R' : undeclared identifier
utilis.cpp(9) : error C2143: syntax error : missing ';' before 'string'
utilis.cpp(9) : error C2059: syntax error : 'string'
utilis.cpp(10) : error C2015: too many characters in constant
utilis.cpp(10) : error C2059: syntax error : ')'
utilis.cpp(11) : error C2059: syntax error : ')'
utilis.cpp(12) : error C2015: too many characters in constant
utilis.cpp(12) : error C2059: syntax error : ')'
utilis.cpp(12) : warning C4129: '_' : unrecognized character escape sequence
utilis.cpp(12) : error C2001: newline in constant
utilis.cpp(12) : error C2015: too many characters in constant
utilis.cpp(13) : error C2015: too many characters in constant
utilis.cpp(13) : error C2059: syntax error : ')'
utilis.cpp(13) : error C2059: syntax error : ')'
utilis.cpp(14) : warning C4129: ' ' : unrecognized character escape sequence
utilis.cpp(14) : error C2001: newline in constant
utilis.cpp(14) : error C2015: too many characters in constant
utilis.cpp(15) : error C2018: unknown character '0x60'
utilis.cpp(15) : error C2015: too many characters in constant
utilis.cpp(15) : error C2018: unknown character '0x60'
utilis.cpp(15) : error C2137: empty character constant
utilis.cpp(16) : error C2018: unknown character '0x60'
utilis.cpp(16) : error C2015: too many characters in constant
utilis.cpp(17) : error C2015: too many characters in constant
utilis.cpp(17) : warning C4129: ' ' : unrecognized character escape sequence
utilis.cpp(17) : error C2001: newline in constant
utilis.cpp(17) : error C2015: too many characters in constant
utilis.cpp(18) : error C2018: unknown character '0x60'
utilis.cpp(18) : error C2015: too many characters in constant
utilis.cpp(18) : error C2018: unknown character '0x60'
utilis.cpp(18) : error C2015: too many characters in constant
utilis.cpp(18) : error C2018: unknown character '0x60'
utilis.cpp(18) : error C2015: too many characters in constant
utilis.cpp(18) : error C2001: newline in constant
utilis.cpp(21) : error C2143: syntax error : missing ')' before '{'
utilis.cpp(21) : error C2143: syntax error : missing ';' before '{'
utilis.cpp(21) : error C2447: '{' : missing function header (old-style formal list?)
对于无法创建多行字符串的问题,我做错了什么?
我也尝试过:cout << BANNER
并获得相同的输出。对我来说,to many characters in constant
错误没有意义,因为我看过比我大的横幅,例如见here。
答案 0 :(得分:3)
问题是你放[]
const char *BANNER[] = R"BANNER(
应该是
const char *BANNER = R"BANNER(
另外,使用C ++ 11或更高版本。
使用带有-std=c++11
的g ++为我工作。