C++:如何在标准上放置多行::字符串数据("here");
C++: How to put multiple lines on std::string data("here");
我需要写一个。批处理文件;我如何插入多行?
参见:std::string data(");
#include <iostream>
#include <fstream>
#include <string>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
int name;
std::cout << "Insert your name";
std::cin >> name;
const char *path="C:/Users/Public/Desktop/file.bat";
std::ofstream file(path);
std::string data( /* "FIRST LINE + ENTER + SECOND LINE + name + ENTER + THIRD LINE"*/ );
file << data;
}
Thanks in advance
使用n
作为换行符。
std::string data("FIRST LINEnSECOND LINEnTHIRD LINE");
在c++ 11中,您还可以使用原始字符串文字:
std::string data(
R"(line 1
line 2
line 3
...)"
);
相关文章:
- C++浮点数据类型和字符串数据类型无法子到模板函数中
- C++ - 使用用户输入的字符串数据检查结构字符串数据(无限执行 while 循环)
- 如果我在块中编写字符串文字,是否会从数据部分复制整个字符串数据?
- 无法在 c++ 中将字符串分配给字符串数据类型
- 将特定字符串数据解析为变量
- C++ 将字符串数据包转换为 iphdr语言 - 字符串数据包的格式应该是什么?
- 基于给定字符串数据类型的链表删除节点
- 插入了 C++ 数组字符串数据,但在显示输出时不显示
- 使用来自串行端口的字符串数据来操作振镜扫描仪在更高的速度下会出错
- 将元音与字符串数据类型的字符串分开,并将其存储在新字符串中
- 放置在外部 DLL 中的类中的字符串数据的内存损坏
- 创建字符串数据串起
- 如何在C++中将字符串数据存储在字符串 2D 数组中
- C++程序不返回文件中文本和字符串数据的值
- C++:在字符串数据类型中创建单词"letter after letter"
- 将向量中的字符串数据解析为适当的数据类型 c++
- 如何将提取的字符串数据转换为字符数组
- 字符串数据类型变量初始化
- 如何从本机空间中的宗地中检索字符串数据
- 在C 中使用字符串数据类型的问题