【问题标题】:Visual Studio 2015: Error C2679 binary '>>': no operator foundVisual Studio 2015:错误 C2679 二进制“>>”:未找到运算符
【发布时间】:2016-01-28 07:56:49
【问题描述】:

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

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

我的程序名称是 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;
}

【问题讨论】:

    标签: c++ visual-c++


    【解决方案1】:

    我想你想使用operator&lt;&lt;,而不是operator&gt;&gt;

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

    【讨论】:

    • 如果有助于理解它们,请始终遵循箭头方向。您是想将内容通过管道传输到 myJournal,还是从 myJournal 输出到输出? >> 运算符通常用于将内容从输入流(如 std::cin)发送到变量/输出流:)
    猜你喜欢
    • 1970-01-01
    • 2012-12-25
    • 2015-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多