Hello! I'm trying to write a program, that replaces inscpitions like "\input{C:\FullFileName.txt}" to maintenance of FullFileName.txt. It now looks like

#include <fstream>

using namespace std;
#define shint short unsigned int 

const char* InS ="input{";

ofstream log ("C:\\Users\\DimOK\\Desktop\\Lat\\TEST1\\log.txt");

bool EqN (ifstream &as, const char *ba, shint l){...} // takes l chars from as. True if they're equall to ba;


int main()
{
 	log << "\nThe begining."; // this isn't writing to file. WHY?
 	ifstream i ("C:\\Users\\DimOK\\Desktop\\Lat\\TEST1\\Square_Equals_Task.tex");
 	ofstream o ("C:\\Users\\DimOK\\Desktop\\Lat\\TEST1\\Square_Equals_Task2.tex");
             //some other code
	 o.put(i.get());//is this correct? Are there such overloads in std?

 	return 0;
}

The program finishes incorrectly and nothing is writen to log.
I would be glad to hear some advice about how to do it easier.
P.S. Sorry for my strange language.

VernonDozier commented: Code tags on first post! +18
#include "fstream"
#include "iostream"

has to be:

#include <fstream>
#include <iostream>

Edit::
Why are you using a preprocessor macro? typedef would be a more accepted way :)

Edit:: OP edited/clarified his post, so I removed some things from mine as well :P

Does this simple program run correctly on your computer?

#include <fstream>

int main()
{
    std::ofstream fout("test.txt");
    fout << "Hello World!\n";
}

Check if the program creates a file called test.txt, and check whether it contains: Hello World!.
If this program runs fine, then try and check whether the following runs correctly:

#include <fstream>

int main()
{
    std::ofstream fout("C:\\Users\\DimOK\\Desktop\\Lat\\TEST1\\test.txt");
    fout << "Hello World!\n";
}

Edit:: Depending on the location were you run my first example from, it might be good to delete test.txt before running the second test program.

As expected, theese work correctly.
And this one too:

#include <fstream>
 
std::ofstream fout("C:\\Users\\DimOK\\Desktop\\Lat\\TEST1\\test.txt");

int main()
{
    fout << "Hello World!\n";
}

You might want to try recompiling your source.
In case recompiling doesn't solve the problem: Could you post your whole code, so I can check on my implementation?

It was already recompiled several times.
The whole code now is

#include <fstream>

using namespace std;
typedef short unsigned int shint;

const char* InS ="input{";

ofstream logs ("log.txt");

bool EqN (ifstream &as, const char *ba, shint l)
{logs << "\nin EqN";
char c, Buf[l+1], *a=Buf, *b =(char*) ba;
for (int t =0; t<l && as;t++)
{as.get(c);
*a=c;
a++;}
a = '\0';
logs << "\na: "<< a;
logs << "\nba: "<< ba;
for (shint t=0; *(a++)==*(b++) && t<l;t++)
if (*(--a)==*(--b)) return 1;
else return 0;
}


int main()
{
 	logs << "\nThe begining.";
 	ifstream i ("Square_Equals_Task.tex");
 	ofstream o ("Square_Equals_Task2.tex");
 	logs << "\nBefore while.";
 	while (i)
 	{logs << "\nBefore hard if.";
 	if (i.get()=='\\')
     {if (EqN(i, InS, 6))
	 {logs << "\nif true.";
	 char c, FN[500], *fn=FN;
	 i.get (c);
	 while (c!='}'){if (c!='/')*(fn++)=c; else *(fn++)='\\';}
	 *fn='\0';
	 ifstream it (fn);
	 while (it) o.put(it.get());
	 }
	 else {logs << "\nif false.";o.put(i.get());}//{char c; i.get(c); o.put(c);}
  	}
	 else {logs << "\nif false.";o.put(i.get());}//{char c; i.get(c); o.put(c);}
  	}
 	return 0;
}

Well, with me, your code correctly writes to the log file (I'm using MinGW as compiler), though I couldn't fully test the code because I don't have the input file: Square_Equals_Task.tex.

The log-file created on my computer looks like:

The begining.
Before while.

What you could try is: create a new source file, copy all the code from your current file into it, compile the new file, and see whether the newly generated executable runs fine.
This may sound ridiculous, but I've seen such a problem before, and guess: it worked!

Hopefully, in my case it still doesn't work from the new file.
I'm trying to use VS2008 but on this code it gives "error C2871: 'std' : a namespace with this name does not exist"

I got it: I needed to flush my log stream, because the programm was crashing before overfulling of the buffer.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.