473,659 Members | 3,162 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Read, write, append and delete text file over network.

9 New Member
Hi
I need help with to access a text file over my local network.
I need to be able to create,read, write and delete the txt file on a specific machine(s) from any computer over the network. The folder where the txt file should be created is enabled for sharing and allows other users on the network to change files (XP Pro on all machines). My code is as follows:
Expand|Select|Wrap|Line Numbers
  1. // Writing Local IP to File
  2.   fstream myfile;
  3.   myfile.open ("\\computer_name\\folder_name\\test2.txt");
  4.   myfile << localIP;
  5.   myfile.close();
  6. //////////////////////////////////////////////////////////////////
  7. //Reading from File for Local IP
  8. string line;
  9.   fstream myfile ("\\computer_name\\folder_name\\test2.txt");
  10.   if (myfile.is_open())
  11.   {
  12.     while (! myfile.eof() )
  13.     {
  14.       getline (myfile,line);
  15.       cout << line << endl;
  16.     }
  17.     myfile.close();
  18.   }
  19.  
I don't seem to be able to create, read, write, etc the file using
Expand|Select|Wrap|Line Numbers
  1. fstream myfile;
  2.   myfile.open ("\\computer_name\\folder_name\\test2.txt");
  3.  
It seems like the path is wrong although if I paste the path into 'RUN' I obtain the correct folder/file.
Can you please help with this. Also I need help on deleting the file after reading.
Thank you
S
Jul 18 '07 #1
6 9763
JosAH
11,448 Recognized Expert MVP
Hi
I need help with to access a text file over my local network.
I need to be able to create,read, write and delete the txt file on a specific machine(s) from any computer over the network. The folder where the txt file should be created is enabled for sharing and allows other users on the network to change files (XP Pro on all machines). My code is as follows:
Expand|Select|Wrap|Line Numbers
  1. // Writing Local IP to File
  2.   fstream myfile;
  3.   myfile.open ("\\computer_name\\folder_name\\test2.txt");
  4.   myfile << localIP;
  5.   myfile.close();
  6. //////////////////////////////////////////////////////////////////
  7. //Reading from File for Local IP
  8. string line;
  9.   fstream myfile ("\\computer_name\\folder_name\\test2.txt");
  10.   if (myfile.is_open())
  11.   {
  12.     while (! myfile.eof() )
  13.     {
  14.       getline (myfile,line);
  15.       cout << line << endl;
  16.     }
  17.     myfile.close();
  18.   }
  19.  
I don't seem to be able to create, read, write, etc the file using
Expand|Select|Wrap|Line Numbers
  1. fstream myfile;
  2.   myfile.open ("\\computer_name\\folder_name\\test2.txt");
  3.  
It seems like the path is wrong although if I paste the path into 'RUN' I obtain the correct folder/file.
Can you please help with this. Also I need help on deleting the file after reading.
Thank you
S
Shouldn't you make the path like this:

Expand|Select|Wrap|Line Numbers
  1.   myfile.open ("\\\\computer_name\\folder_name\\test2.txt");
  2.  
kind regards,

Jos
Jul 18 '07 #2
000dreamsound000
9 New Member
Shouldn't you make the path like this:

Expand|Select|Wrap|Line Numbers
  1.   myfile.open ("\\\\computer_name\\folder_name\\test2.txt");
  2.  
kind regards,

Jos
Thanks for the quick reply. I had tried ("\\\\computer_ name.....") before and it didn't work. I tried it again but no luck. I can't figure out what I'm doing wrong.
Thanks for any suggestions
Jul 18 '07 #3
000dreamsound000
9 New Member
Seems like it wasn't liking fstream to write to the txt file in the first place.Changed to ifstream and all fine
Thanks
Jul 18 '07 #4
weaknessforcats
9,208 Recognized Expert Moderator Expert
Seems like it wasn't liking fstream to write to the txt file in the first place.Changed to ifstream and all fine
Thanks
Did you open your fstream as an output file:
Expand|Select|Wrap|Line Numbers
  1. myfile.open ("\\\\computer_name\\folder_name\\test2.txt", ios_base::out);
  2.  
???
Jul 18 '07 #5
000dreamsound000
9 New Member
Did you open your fstream as an output file:
Expand|Select|Wrap|Line Numbers
  1. myfile.open ("\\\\computer_name\\folder_name\\test2.txt", ios_base::out);
  2.  
???
No, I didn't use 'ios::' at all. I am just a beginner at C++ and I couldn't tell you what was going wrong. But everything seems fine now.
Thanks for your help.
Jul 23 '07 #6
000dreamsound000
9 New Member
No, I didn't use 'ios::' at all. I am just a beginner at C++ and I couldn't tell you what was going wrong. But everything seems fine now.
Thanks for your help.
Also fstream specifies ios::out and ios::in as default. And ofstream-ios::out.
ifstream-ios::in.
Cheers
Jul 23 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
8582
by: burdeen | last post by:
I can't find any way of writing a unicode, or UTF-8 format text file. Right now i have a Unicode string that i write to the text file and the unicode characters are replaced with ANSI question marks '?'. Please, How do i accomplish this? I've been searching for a solution for weeks... why has nobody even asked this question? shouldn't it be a FAQ?
3
2383
by: NewToPHP | last post by:
I am COMPLETELY NEW TO PHP San someone supply me with a PHP script to read and write to a text file on the server Also any suggestion on a free PHP editor?
4
2195
by: Feng Chun | last post by:
Hi, need help for this. In asp.net, when I do a load balancing on my website, which means there are 2 or more servers behind, one of my webpage needs to read/write a temp file in the server. But the client's first request may go to the first server, but the second request goes to the second server, so there is a chance that the request could not find the correct file to read/write. how to solve this issue?
2
1217
by: Pramod Kumar | last post by:
Dear All, I want to read data from a text file using Stream Reader. Please tell me the .DLL file to be added for the same. Regards, Pramod
2
8588
by: Roy Gourgi | last post by:
Hi, How could I append a text file to another text file. Let's say that I have a File1 and I want to append File2 at the end of File1, how would I do that? TIA Roy
14
16965
by: Niron kag | last post by:
Hello ! With c# , I want to write to a text file in a specific font and color. Any ideas ? Thanks...
4
3325
by: mvvdsteen | last post by:
Hello all, I'm quite new to c++. I made a small program that will help me analyse wind tunnel data. But now I want this program to write to a text file. This works just fine, except it discards whatever is in the textfile at that time. I open the file, and then I go to the end, and write the stuff. I came up with the following code: ofstream logfile; logfile.open ("HWlog.txt"); logfile.seekp (0, ios::end); logfile << " " << endl;
6
418
by: rohit | last post by:
Hi All, I am new to C language.I want to read integers from a text file and want to do some operation in the main program.To be more specific I need to multiply each of these integers with another set of integers stored in an array.It would be a great help if you could provide some code for it.I tried the function fscanf but by that I am able to read only the first integer of the text file.Please help me.
1
4739
by: mamul | last post by:
Hi All, I am able to read and write to .txt, .bin files. but the same program is not support for .docx file . can someone help me the procedure to perform read write operation on .docx file. please give me some exmple or if u have solve this type of problem in c++ then please reply me. Thanks, Mamul
0
8337
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8748
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8531
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8628
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2754
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.