Search code examples
c++stringqtmingwofstream

Error in ofStream, Qt 5.14.2 can 't write string into file


I am trying to write my program from VS (MVCS) for Qt(MinGb) I am using ofstream and has a following code:

#include <fstream>
#include <string>
#include <iostream>
#include <exception>
using namespace std;
void WriteToFile(ofstream* fileToWrite, std::string StringNeedsToWrite)
{
    if (fileToWrite)
    {
        if (IsStartOfNewString(StringNeedsToWrite))
        {
            *fileToWrite << '\n';
        }
        *fileToWrite << StringNeedsToWrite;     
    }
    else
    {
        throw exception();
    }
}

I want to write string into file, and set ofstream into my method. But i have a strange error and don't know how to fix it (on image)

Error on image


Solution

  • They differ in their make files and project files. A common problem is that moving a project from one environment to another entails big mistakes. For example, MinGW under Linux does not have standard streams, but there is windows.h.

    Such problems should be taken into account and studied at the stage of developing a program architecture and choosing technologies for development.

    Frequent practice has shown that Qt is best used with your IDE and, if possible, use its classes for development.