gpt4 book ai didi

c++ - Visual Studio 2015 : Error C2679 binary '>>' : no operator found

转载 作者:搜寻专家 更新时间:2023-10-31 02:17:58 25 4
gpt4 key购买 nike

所以这是我的问题...当我尝试在 Visual Studio 中写入 .txt 文件时遇到此错误。在命令提示符下,它给了我这个错误:“c:\users\carter\documents\visual studio 2015\Projects\JournalEntry\Debug\JournalEntry.exe”不是内部或外部命令、可运行程序或批处理文件

这是我在 Visual Studio 中遇到的错误:错误 C2679 二进制“>>”:第 18 行未找到接受类型为“const char [24]”的右手操作数(或没有可接受的转换)的运算符

我的程序名称是 JournalEntry.cpp,我要做的就是写入名为 Journal.txt 的文件

这是我的代码:

// JournalEntry.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h>

using namespace std;

int main()
{
fstream myJournal;
myJournal.open("Journal.txt");
if (myJournal.is_open())
{
myJournal >> "This is my first line! ";
myJournal.close();
}
else
{
cerr << "Error opening file ";
exit(1);
}

return 0;
}

最佳答案

我想你想使用 operator<< , 不是 operator>> .

myJournal << "This is my first line! ";
~~

关于c++ - Visual Studio 2015 : Error C2679 binary '>>' : no operator found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35055724/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com