Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String C++;cout或wcout字符串包含\";isn';不要拆线_String_C++11_Winapi_Cout_Tdm Gcc - Fatal编程技术网

String C++;cout或wcout字符串包含\";isn';不要拆线

String C++;cout或wcout字符串包含\";isn';不要拆线,string,c++11,winapi,cout,tdm-gcc,String,C++11,Winapi,Cout,Tdm Gcc,C++11,编译器为TDM-GCC 我用WinAPI制作了一个ini文件并从中读取字符串(UCS-2 LE BOM), GetPrivateProfileStringW [String] Example = Today\nYesterday\nApple 我的函数库将返回一个变量std::wstring。看起来不错。 然后使用wcout,就像: #include <iostream> #include <string> using namespace std; wst

C++11,编译器为TDM-GCC

我用WinAPI制作了一个ini文件并从中读取字符串(UCS-2 LE BOM), GetPrivateProfileStringW

[String]
Example = Today\nYesterday\nApple
我的函数库将返回一个变量std::wstring。看起来不错。 然后使用wcout,就像:

#include <iostream>
#include <string>

using namespace std;
wstring readString = GetPrivateProfileStringW();    // Hide the details.
wcout << readString << endl;
我想要的是:

Today
Yesterday
Apple
我不确定为什么“\n”在这种情况下不起作用

为了避免这种情况,我可以创建多个INI键,并使用“endl”将它们删除

但是在这个项目中,有多少行是动态的


如何将屏幕上Windows API中的单个字符串变量变为多行?

序列
\n
仅由编译器在源代码中识别为文本字符串或字符的一部分。它不是内置在库或任何标准函数中的


如果希望序列表示从外部源读取的输入中的换行符,则必须自己处理。

“\n”
由编译器转换,而不是
wcout
。您的INI文件未通过编译器。这些字符是逐字书写的。这是预期的行为。如果你想换行,你必须自己解析字符串。@I非常感谢,我会按照你的建议去做。看起来这比我想象的要复杂。非常感谢。也许找到一些代码库是一个好主意…@2bpern它可能只是简单地将字符串
“\\n”
替换为实际的换行符
“\n”
一点也不难。我知道\\n来自其他编程语言python等。不是我,Windows API添加了\\。我想我应该在INI中添加一些特殊标记,并在源代码中用\n替换它们。@2b不能使用双反斜杠作为路径分隔符,但因为如果您查找
“\n”
,编译器会用一个换行符替换它,而这是您找不到的。您必须转义反斜杠,以便编译器实际搜索实际的反斜杠字符,该字符后跟
'n'
。试试看,例如
std::cout谢谢!\\n到\n转换功能已完成!
Today
Yesterday
Apple