最近我一直在做一个项目,遇到一个问题,我需要不断地将 a 复制const wchar*到wstring. 有没有什么方法可以将指针“移动”到字符串中,这样它就不会复制它?
我希望有一种直接的方法来做到这一点,但我未能找到任何关于此的资源
我一直在从事一个需要从 .txt 文件读取文本的项目。但我在控制台中显示了两次文本。
这是CreateFiles.cpp
#include "CreateFiles.h"
void createF()
{
std::fstream fs{ "C:\\Users\\bahge\\source\\repos\\Education\\Education\\myfile.txt" };
std::string s;
while (fs)
{
std::getline(fs, s);
std::cout << s << std::endl;
}
}
Run Code Online (Sandbox Code Playgroud)
和CreateFiles.h
#pragma once
#ifndef CREATE_FILES
#define CREATE_FILES
#include <iostream>
#include <fstream>
#include <string>
void createF();
#endif // !CREATE_FILES
Run Code Online (Sandbox Code Playgroud)
这是文件的内容
StackOverflow
Run Code Online (Sandbox Code Playgroud)
以及控制台的输出
StackOverflow
StackOverflow
C:\Users\bahge\source\repos\Education\x64\Debug\Education.exe (process 39072) exited with code 0.
Press any key to close this window . . .
Run Code Online (Sandbox Code Playgroud)