I manage to write code in C++ that works what is needed. Ill paste it down. But its console application and i need windows form application. So i tried to do it in the visual studio 2017 and C#.
I need an application that will post on screen, only last line from .txt file but that .txt file needs to be editable while app is running. So when i add new line in .txt and hit ctrl+s it will automaticly update results in app and it will not show me
"NOTEPAD: The process cannot access the file becouse it is being used by another process."
This is the C++ code that works perfect:
std::ifstream ifs("test.log");
if (ifs.is_open())
{std::string line;
while (true)
{while (std::getline(ifs, line)) std::cout << line << "\n";
if (!ifs.eof())
break;
ifs.clear();
}
}
return 0;}
it returns last line from test.log file and when i paste new one in test file it automaticly change after saving the changes in test.txt file.
And here is the code that i write in C# and it works BUT after i run it it wont allow me to save changes in file that i ame making changes.
CODE:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Text;
using System.IO;
namespace lastone
{
public partial class last : Form
{
public last()
{
InitializeComponent();
}
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
Stream myStream;
OpenFileDialog openFileDialog1 = new OpenFileDialog();
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
{
if ((myStream = openFileDialog1.OpenFile()) != null)
{
string strfilename = openFileDialog1.FileName;
richTextBox1.Text = File.ReadLines(strfilename).Last();
}
}
}
}
}
}
In this case i load test.txt file with button and openfiledialog... and then just printout last line in richTextbox.
Can anyone give me advice how to make test.txt file editable while my app is working? And eaven if i manage to bypass that problem how can i make the app that i dont need to open file all over again to finde changes in test.txt? i need it to "refresh" automaticly...
P.S. i am literally NEW to programing so dont judge me :) and i am not native eng speaker so sorry for mistakes. I googled so much stuff that i am only confused... TY for any help.