小编Bah*_*Goz的帖子

如何有效地将 const wchar* 移动到 std::wstring 中?

最近我一直在做一个项目,遇到一个问题,我需要不断地将 a 复制const wchar*wstring. 有没有什么方法可以将指针“移动”到字符串中,这样它就不会复制它?

我希望有一种直接的方法来做到这一点,但我未能找到任何关于此的资源

c++

2
推荐指数
1
解决办法
80
查看次数

为什么文件的文本显示两次

我一直在从事一个需要从 .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)

c++ c++20

1
推荐指数
1
解决办法
69
查看次数

标签 统计

c++ ×2

c++20 ×1