K
K
kytcenochka2018-05-03 10:04:50
C++ / C#
kytcenochka, 2018-05-03 10:04:50

The values ​​are not written to the file. Why? c++?

Only commas are written.
I share everything, because I need a library that will receive data and write files of a certain structure. Could this be the wrong approach?
I'm learning, maybe a stupid question
main.cpp

#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>
#include "function.h"
using namespace std;


int main()
{
    struct Station st_ation;
    st_ation.station_name="Station name";
    st_ation.rec_dew="1";
    st_ation.year="2001";
   writefirstline();
}

function.h
struct Station
{ 
    std::string station_name; 
    std::string rec_dew; 
    std::string year;
};
void writefirstline();

function1.cpp
#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>
#include <vector>

#include "function.h"
using namespace std;

 struct Station station;
void writefirstline(){
ofstream file("fileConfiguration.cfg");
file<<station.station_name<<","<<station.rec_dew<<","<<station.year<<"\n";
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Bogdan, 2018-05-03
@4elovek37

Your station you are writing is empty. Maybe it's worth passing the station being recorded as a parameter to the function?
Or declare station in function1.cpp as extern, you can read more in any textbook.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question