大侠们来看一下这个错误

kangtianwang 2010-12-15 01:14:59
貌似是字符集问题,但不知道怎么弄,所以来向大家求助

const char* kTeststr_ks =
"नेपाल एसिया "
"मंज अख मुलुक"
" राजधानी काठ"
"माडौं नेपाल "
"अधिराज्य पेर"
"ेग्वाय "
"दक्षिण अमेरि"
"का महाद्वीपे"
" मध् यक्षेत्"
"रे एक देश अस"
"् ति फणीश्वर"
" नाथ रेणु "
"फिजी छु दक्ष"
"िण प्रशान् त"
" महासागर मंज"
" अख देश बहाम"
"ास छु केरेबि"
"यन मंज "
"अख मुलुख राज"
"धानी नसौ सम्"
" बद्घ विषय ब"
"ुरुंडी अफ्री"
"का महाद्वीपे"
" मध् "
"यक्षेत्रे दे"
"श अस् ति सम्"
" बद्घ विषय";

error C2001: 常量中有换行符




...全文
118 21 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
kangtianwang 2010-12-15
  • 打赏
  • 举报
回复
谢谢大虾,嘿嘿
[Quote=引用 18 楼 luciferisnotsatan 的回复:]

引用 14 楼 kangtianwang 的回复:

我怀疑是字符集设置问题,但不知道咋改引用 12 楼 luciferisnotsatan 的回复:

Error Message
newline in constant


A string constant cannot be continued on a second line unless you do the follo……
[/Quote]
luciferisnotsatan 2010-12-15
  • 打赏
  • 举报
回复
也可以用下面的写法
const TCHAR* kTeststr_ks =
_T("नेपाल एसिया ")
_T("मंज अख मुलुक")
luciferisnotsatan 2010-12-15
  • 打赏
  • 举报
回复
[Quote=引用 17 楼 kangtianwang 的回复:]

额...回复错了,嘿嘿,但是那阿拉伯字符为什么就不可以呢?如果是字符集设置的问题该如何去改?引用 15 楼 luciferisnotsatan 的回复:

引用 13 楼 kangtianwang 的回复:

为什么下边这个就可以
const char* kTeststr_en =
"confiscation of goods is assigned as the penalty p……
[/Quote]
不清楚,但我用vs2005,unicode工程,编译的时候,弹了个框出来,说什么字符转换(没仔细看),选了yes,编译没问题

这文体应该用宽字符吧。改成宽字符后,加上afxmessagebox输出,编译也没问题。消息框能显示这文字,看上去文字是对的。

const wchar_t* kTeststr_ks =
L"नेपाल एसिया "
L"मंज अख मुलुक"
L" राजधानी काठ"
L"माडौं नेपाल "
L"अधिराज्य पेर"
L"ेग्वाय "
L"दक्षिण अमेरि"
L"का महाद्वीपे"
L" मध् यक्षेत्"
L"रे एक देश अस"
L"् ति फणीश्वर"
L" नाथ रेणु "
L"फिजी छु दक्ष"
L"िण प्रशान् त"
L" महासागर मंज"
L" अख देश बहाम"
L"ास छु केरेबि"
L"यन मंज "
L"अख मुलुख राज"
L"धानी नसौ सम्"
L" बद्घ विषय ब"
L"ुरुंडी अफ्री"
L"का महाद्वीपे"
L" मध् "
L"यक्षेत्रे दे"
L"श अस् ति सम्"
L" बद्घ विषय";
AfxMessageBox(kTeststr_ks);
luciferisnotsatan 2010-12-15
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 kangtianwang 的回复:]

我怀疑是字符集设置问题,但不知道咋改引用 12 楼 luciferisnotsatan 的回复:

Error Message
newline in constant


A string constant cannot be continued on a second line unless you do the following:

End the first line w……
[/Quote]
把整个和成一行。或者用 \ 提示
const char *xx =
" aa \
\r\n \
bb ";

就一组引号,中间每行用 \ 结束,\后就是回车,没有其他空白符
kangtianwang 2010-12-15
  • 打赏
  • 举报
回复
额...回复错了,嘿嘿,但是那阿拉伯字符为什么就不可以呢?如果是字符集设置的问题该如何去改?[Quote=引用 15 楼 luciferisnotsatan 的回复:]

引用 13 楼 kangtianwang 的回复:

为什么下边这个就可以
const char* kTeststr_en =
"confiscation of goods is assigned as the penalty part most of the courts "
"consist of members and when it is necessary to bring ……
[/Quote]
kangtianwang 2010-12-15
  • 打赏
  • 举报
回复
不知道应该设置为什么字符集,还请大虾指教啊[Quote=引用 6 楼 luciferisnotsatan 的回复:]

什么文字?这一串是一个字符串?
const char *xx =
"aa"
"\r\n"
"bb";
这样写代码没问题。怀疑是你字符集的问题
[/Quote]
luciferisnotsatan 2010-12-15
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 kangtianwang 的回复:]

为什么下边这个就可以
const char* kTeststr_en =
"confiscation of goods is assigned as the penalty part most of the courts "
"consist of members and when it is necessary to bring public cases before a "……
[/Quote]
这样写当然是可以的,前面我己经说了。
kangtianwang 2010-12-15
  • 打赏
  • 举报
回复
我怀疑是字符集设置问题,但不知道咋改[Quote=引用 12 楼 luciferisnotsatan 的回复:]

Error Message
newline in constant


A string constant cannot be continued on a second line unless you do the following:

End the first line with a backslash.

Close the string on the first ……
[/Quote]
kangtianwang 2010-12-15
  • 打赏
  • 举报
回复
为什么下边这个就可以
const char* kTeststr_en =
"confiscation of goods is assigned as the penalty part most of the courts "
"consist of members and when it is necessary to bring public cases before a "
"jury of members two courts combine for the purpose the most important cases "
"of all are brought jurors or";
[Quote=引用 1 楼 jackyjkchen 的回复:]

不是字符集问题,是语法问题

如果你想要多维字串

应该这样定义{"xx","yy"}

如果你想要字符串内用",应该"x\"y",用转义符号
[/Quote]
luciferisnotsatan 2010-12-15
  • 打赏
  • 举报
回复
Error Message
newline in constant


A string constant cannot be continued on a second line unless you do the following:

End the first line with a backslash.

Close the string on the first line with a double quotation mark and open the string on the next line with another double quotation mark.

Ending the first line with \n is not sufficient.

Example
The following sample generates C2001:

Copy Code
// C2001.cpp
// C2001 expected
#include <stdio.h>

int main()
{
printf_s("Hello,
world");
printf_s("Hello,\n
world");
}


Spaces at the beginning of the next line after a line-continuation character are included in the string constant. None of the examples shown above embed a newline character into the string constant. You can embed a newline character as shown here:

Copy Code
// C2001b.cpp
#include <stdio.h>

int main()
{
printf_s("Hello,\n\
world");

printf_s("Hello,\
\nworld");

printf_s("Hello,\n"
"world");

printf_s("Hello,"
"\nworld");

printf_s("Hello,"
" world");

printf_s("Hello,\
world");
}

不过你这字符串每行都有 " 结束, 应该没错,除非被前面的阿拉伯文吃了
hastings 2010-12-15
  • 打赏
  • 举报
回复
第一次见到这么帅的文字~~
luciferisnotsatan 2010-12-15
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 luciferisnotsatan 的回复:]

什么文字?这一串是一个字符串?
const char *xx =
"aa"
"\r\n"
"bb";
这样写代码没问题。怀疑是你字符集的问题
[/Quote]
这么写,编译器会忽略空白符,把它作为一个字符串,等价
const char *xx = "aa\r\nbb";
kangtianwang 2010-12-15
  • 打赏
  • 举报
回复
Google浏览器的源代码[Quote=引用 6 楼 luciferisnotsatan 的回复:]

什么文字?这一串是一个字符串?
const char *xx =
"aa"
"\r\n"
"bb";
这样写代码没问题。怀疑是你字符集的问题
[/Quote]
太乙 2010-12-15
  • 打赏
  • 举报
回复
在每行的末尾加上续行符号即可。。。
kangtianwang 2010-12-15
  • 打赏
  • 举报
回复
阿拉伯文字[Quote=引用 4 楼 hqin6 的回复:]

什么文?藏文?
[/Quote]
luciferisnotsatan 2010-12-15
  • 打赏
  • 举报
回复
什么文字?这一串是一个字符串?
const char *xx =
"aa"
"\r\n"
"bb";
这样写代码没问题。怀疑是你字符集的问题
kangtianwang 2010-12-15
  • 打赏
  • 举报
回复
我先试一下[Quote=引用 1 楼 jackyjkchen 的回复:]

不是字符集问题,是语法问题

如果你想要多维字串

应该这样定义{"xx","yy"}

如果你想要字符串内用",应该"x\"y",用转义符号
[/Quote]
太乙 2010-12-15
  • 打赏
  • 举报
回复
什么文?藏文?
shadowlsj 2010-12-15
  • 打赏
  • 举报
回复
同楼上。
const char* kTeststr_ks = "नेपाल एसिया ";//只能初始化一个字串。
多字串并要用指针的话,还是考虑链表吧。
liutengfeigo 2010-12-15
  • 打赏
  • 举报
回复
"नेपाल एसिया "
"मंज अख मुलुक"
" राजधानी काठ"
"माडौं नेपाल "
"अधिराज्य पेर"
"ेग्वाय "
"दक्षिण अमेरि"
"का महाद्वीपे"
" मध् यक्षेत्"
"रे एक देश अस"
"् ति फणीश्वर"
" नाथ रेणु "
"फिजी छु दक्ष"
"िण प्रशान् त"
" महासागर मंज"
" अख देश बहाम"
"ास छु केरेबि"
"यन मंज "
"अख मुलुख राज"
"धानी नसौ सम्"
" बद्घ विषय ब"
"ुरुंडी अफ्री"
"का महाद्वीपे"
" मध् "
"यक्षेत्रे दे"
"श अस् ति सम्"
" बद्घ विषय";
加载更多回复(1)

65,192

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧