File operations

Pages: 12
I made it well, the process monitor app. It is working perfect i choosed a folder and manually created a text file and Process Monitor App showed it to me after delete. But there is nothing about my program's text file. It couldn't catch something about that. Also closed Anti-virus apps.
Last edited on
D:\TEST
0Enter your nickname: ss
success
write success
The user is succesfully added!
Volume in drive D is Depo

Directory of D:\TEST

26.05.2020 18:06 <DIR> .
26.05.2020 18:06 <DIR> ..
26.05.2020 18:06 713 deneme.cpp
26.05.2020 18:06 1.922.352 deneme.exe
26.05.2020 18:07 28 users.txt
3 File(s) 1.923.093 bytes
2 Dir(s) 204.726.333.440 bytes free


This is proof that you're creating the file. That means you must be deleting it later in your program. It's also possible, but unlikely, that your disk is corrupt.

Can you post the full program? Without the code we're just guessing.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <string>

using namespace std;

void adding() {
    string userName;
    cout << "Enter your nickname: ";
    cin >> userName;
    ofstream userFile;
    userFile.open("users.txt", ios::app);
    userFile<< userName;
    userFile.close();
    cout<<"The user is succesfully added!"<<endl;
}

int main()
{
	cout<<system("cd");
    adding();
}


Already this doesn't even work. Also I have some problems about reading writing permissions, this is why try to work it on D: disc with giving all permissions to all users for directory folder, when i try to edit any text file on C: ProgramFiles, it gives me error like You don't have a permission to open this. I don't know is that related or not.
Yes in C:\Program Files you don't have write permissions, so better avoid it.
Run this code and show us the output please.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <fstream>
#include <stdlib.h>
#include <string>
#include <cstdio>

using namespace std;

void adding()
{
  string userName;
  cout << "Enter your nickname: ";
  cin >> userName;
  ofstream userFile;
  userFile.open("users.txt", ios::app);
  if (!userFile)
  {
    perror(nullptr);
    return;
  }
  userFile << userName;
  userFile.close();
  cout << "The user is succesfully added!" << endl;
}

int main(int argc, char *argv[])
{
  if (argv[0] != nullptr)
    cout << "Program " << argv[0] << " has started.\n";
  adding();
}
Nullptr error, i guess i must change compiler for use it but i don't know how to do. Is there another way to declare it?
What compiler do use?
Comment line 27-28 and see what output you get.
There is another nullptr in 17. line.
It is TDM-GCC 4.9.2 , it came with DevC++.
So why can't you just replace those nullptr with something that your compiler does understand? It would be trivial to do.
Just i had to use folder functions for my homework project I couldn't solve it after a few days, I don't have enough time. So i lost my concentration because only adding function of users class is working on my codes but my mission was do adding, deleting, listing, searching, updating for users and messages classes. Also heredity too. But on my codes only user adding function is working true... I lost my concentrate about to solve text problem, the same goes for the project, though...
Big bad point is waiting for me. Big misfortune.
Normally it should know c++11, but ok.
Try this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <fstream>
#include <stdlib.h>
#include <string>
#include <cstdio>

using namespace std;

void adding()
{
  string userName;
  cout << "Enter your nickname: ";
  cin >> userName;
  ofstream userFile;
  userFile.open("users.txt", ios::app);
  if (!userFile)
  {
    perror("File error");
    return;
  }
  userFile << userName;
  userFile.close();
  cout << "The user is succesfully added!" << endl;
}

int main(int argc, char *argv[])
{
  if (argc > 0 && argv[0] != NULL)
    cout << "Program " << argv[0] << " has started.\n";
  adding();
}
Last edited on
Program D:\TEST\new.exe has started.
Enter your nickname: eee
The user is succesfully added!

It's same with cpp directory.
The Orwell(Bloodshed?) Dev-C++'s compiler has C++11, but not enabled by default because it's old. You can go into the compiler configuration menu and turn on a -std=c++11 or -std=c++0x option. But anyway, that's all beside the point. If that is truly the complete program, then I go back to my previous point that dhayden and I suggested: Something else is deleting your file. I don't know why nor do I have really have more suggestions at this point other than to explore procmon more to see if you can tell which process is deleting your file after it's created.

Do the latest versions of Windows still have a "safe mode" accessible? You could try launching in safe mode and seeing if the problem still happens.
Last edited on
I changed it and this code worked without error.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <fstream>
#include <stdlib.h>
#include <string>
#include <cstdio>
#include <iostream>

using namespace std;

void adding()
{
  string userName;
  cout << "Enter your nickname: ";
  cin >> userName;
  ofstream userFile;
  userFile.open("users.txt", ios::app);
  if (!userFile)
  {
    perror(nullptr);
    return;
  }
  userFile << userName;
  userFile.close();
  cout << "The user is succesfully added!" << endl;
}

int main(int argc, char *argv[])
{
  if (argv[0] != nullptr)
    cout << "Program " << argv[0] << " has started.\n";
  adding();
}


and the output is
Program D:\TEST\new.exe has started.
Enter your nickname: nick
The user is succesfully added!


Is there maybe a transport? Weird an idea but there is not a deleting. At least according to Process Monitor.
Did the code above successfully create the users.txt file?
I don't know what you mean by transport.
If it doesn't deleting according to Process Monitor app, is there maybe something sending it random somewhere. Though when i searched on the computer i still couldn't find it.

No, there isn't users.txtt still.

Also if someone have this or similiar problem, you can use online virtual machines temporarily. At least i used it for finish my project.
Okay. Did you try starting Windows in safe mode and then running the program?
Hello friends after a few days, I don't know how can i start but I found the answer! Please read to the end, because If one day you see another one has this problem, you can help to him.
Okey, I finished my project homework well with a online virtual machine. This is OK. A few minutes ago I tried to install a computer game , It finished to install okey, but when i look to true directory I couldn't find the folders of it. I searched a part of the game on PC and I found weird result, I tried to install 4 times the game and I found 4 folders, but they were not in true directory. They were in "VTRoot Folder" (also it was a secret file in C:) I tried to open game It didn't start, It said you don't have permission to do it in this folder. I searched about it on web, and I found really weird results, It says it is a folder like a "prison". Why is there a folder like that? Is that a part of Windows? No, It is because of my antivirus "Comodo". It wasn't a bad antivirus but a few weeks ago someone said to me don't use it it can make problems, but i didn't delete it still.
Anyway my lost text files were inside of it too, in the "VTRoot" folder.When i found them it was a emotional moment for me. It was very different a folder that you can't open any file or can't change any file inside of it. So If you see someone has the same problem, you should say uninstall Comodo antivirus... This will solve ,I guess. Thanks to everyone tried to help me, I am really grateful to all. For last I was right, there was a transporting :) not deleting. And I guess my harddisk is okey too. My big problem is solved! Again Thanks to everyone!
Last edited on
Yep, over-aggressive anti-virus can do some really nasty things. Glad you were able to find out the root cause, and thanks for following up so that others might know.
Last edited on
Topic archived. No new replies allowed.
Pages: 12