New Posts  All Forums:Forum Nav:

c++ problem

post #1 of 5
Thread Starter 
here is my code
the problem is nothing happens to new.txt
Code:
#include <fstream>
#include <iostream>
#include <string>
using namespace std;

int main()
{
string c,d = "";
fstream reads;
reads.open("R0_1st.txt",ios ::in);
fstream writes;
writes.open("new.txt",ios::in|ios::out);
reads.unsetf(ios::skipws);

while ( getline ( reads, c ) ) {
cout<<c<<endl;
if ( c.find ( "Adiabatic Efficiency" ) != string::npos )

{ 
cout<<">>>>>>>>>>>>>>>"<<endl; //Just to make sure it got here
while( getline (writes,d) )
{
if ( d.find ("replace here") != string::npos )
{
cout<<"<<<<<<<<<<<<<<<"<<endl; //Just to make sure it got here
writes<<c;
}
}
}
}

return 0;
}
Shady
(11 items)
 
  
CPUMotherboardGraphicsRAM
Intel(R) Core(TM) i7-4790K MSI Z97 GAMING 7 (MS-7916)  XFX Radeon R9 295X2 HyperX 32GB 
Hard DriveOSMonitorKeyboard
Kingston SSDNow V300 Series (RAID0) Windows 8.1 Pro Samsung ua40hu7000rxzn (40" UHD) Logitech G105 
PowerCaseMouse
EVGA 850B Corsair Carbide Series Black 500R Mid Tower Logitech G502 
  hide details  
Reply
Shady
(11 items)
 
  
CPUMotherboardGraphicsRAM
Intel(R) Core(TM) i7-4790K MSI Z97 GAMING 7 (MS-7916)  XFX Radeon R9 295X2 HyperX 32GB 
Hard DriveOSMonitorKeyboard
Kingston SSDNow V300 Series (RAID0) Windows 8.1 Pro Samsung ua40hu7000rxzn (40" UHD) Logitech G105 
PowerCaseMouse
EVGA 850B Corsair Carbide Series Black 500R Mid Tower Logitech G502 
  hide details  
Reply
post #2 of 5
You might want to check to see if the files opened successfully.
Code:
reads.open("R0_1st.txt",ios ::in);
if (!reads.is_open())
{
cout << "Unable to open R0_1st.txt" << endl;
return 1;
}

fstream writes;
writes.open("new.txt",ios::in|ios::out);
if (!writes.is_open())
{
cout << "Unable to open new.txt" << endl;
return 2;
}
R
Roped In
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core i7 2600k P8P67 Pro Rev (3.1) @ B3 XFX Radeon HD 6950 XXX 16GB G.SKILL Ripjaws 9-11-9-28 
Hard DriveOptical DriveOSMonitor
2 X Callisto Deluxe 25nm 60GB Plextor PX-B910SA 4x Blu-ray DVD-RW Win7 64 2 x Samsung 275T+ 
KeyboardPowerCaseMouse
Logitech G15 Corsair HX10000 Antec 1200 Logitech G7 
Mouse Pad
Splatter Game Pad 
  hide details  
Reply
Roped In
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core i7 2600k P8P67 Pro Rev (3.1) @ B3 XFX Radeon HD 6950 XXX 16GB G.SKILL Ripjaws 9-11-9-28 
Hard DriveOptical DriveOSMonitor
2 X Callisto Deluxe 25nm 60GB Plextor PX-B910SA 4x Blu-ray DVD-RW Win7 64 2 x Samsung 275T+ 
KeyboardPowerCaseMouse
Logitech G15 Corsair HX10000 Antec 1200 Logitech G7 
Mouse Pad
Splatter Game Pad 
  hide details  
Reply
post #3 of 5
Thread Starter 
I checked
they open successfully.
Shady
(11 items)
 
  
CPUMotherboardGraphicsRAM
Intel(R) Core(TM) i7-4790K MSI Z97 GAMING 7 (MS-7916)  XFX Radeon R9 295X2 HyperX 32GB 
Hard DriveOSMonitorKeyboard
Kingston SSDNow V300 Series (RAID0) Windows 8.1 Pro Samsung ua40hu7000rxzn (40" UHD) Logitech G105 
PowerCaseMouse
EVGA 850B Corsair Carbide Series Black 500R Mid Tower Logitech G502 
  hide details  
Reply
Shady
(11 items)
 
  
CPUMotherboardGraphicsRAM
Intel(R) Core(TM) i7-4790K MSI Z97 GAMING 7 (MS-7916)  XFX Radeon R9 295X2 HyperX 32GB 
Hard DriveOSMonitorKeyboard
Kingston SSDNow V300 Series (RAID0) Windows 8.1 Pro Samsung ua40hu7000rxzn (40" UHD) Logitech G105 
PowerCaseMouse
EVGA 850B Corsair Carbide Series Black 500R Mid Tower Logitech G502 
  hide details  
Reply
post #4 of 5
Place an '\
' at the end of that "new.txt" and R0_1st.txt as if you do not have one there, the put pointer will be placed at the end of the file, so that you will not be able to write at that position. Your file is opening but unable to be written to successfully.
Roped In
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core i7 2600k P8P67 Pro Rev (3.1) @ B3 XFX Radeon HD 6950 XXX 16GB G.SKILL Ripjaws 9-11-9-28 
Hard DriveOptical DriveOSMonitor
2 X Callisto Deluxe 25nm 60GB Plextor PX-B910SA 4x Blu-ray DVD-RW Win7 64 2 x Samsung 275T+ 
KeyboardPowerCaseMouse
Logitech G15 Corsair HX10000 Antec 1200 Logitech G7 
Mouse Pad
Splatter Game Pad 
  hide details  
Reply
Roped In
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core i7 2600k P8P67 Pro Rev (3.1) @ B3 XFX Radeon HD 6950 XXX 16GB G.SKILL Ripjaws 9-11-9-28 
Hard DriveOptical DriveOSMonitor
2 X Callisto Deluxe 25nm 60GB Plextor PX-B910SA 4x Blu-ray DVD-RW Win7 64 2 x Samsung 275T+ 
KeyboardPowerCaseMouse
Logitech G15 Corsair HX10000 Antec 1200 Logitech G7 
Mouse Pad
Splatter Game Pad 
  hide details  
Reply
post #5 of 5
Thread Starter 
how about adding this ?
reads.seekp(ios::beg);
writes.seekp(ios::beg);
Shady
(11 items)
 
  
CPUMotherboardGraphicsRAM
Intel(R) Core(TM) i7-4790K MSI Z97 GAMING 7 (MS-7916)  XFX Radeon R9 295X2 HyperX 32GB 
Hard DriveOSMonitorKeyboard
Kingston SSDNow V300 Series (RAID0) Windows 8.1 Pro Samsung ua40hu7000rxzn (40" UHD) Logitech G105 
PowerCaseMouse
EVGA 850B Corsair Carbide Series Black 500R Mid Tower Logitech G502 
  hide details  
Reply
Shady
(11 items)
 
  
CPUMotherboardGraphicsRAM
Intel(R) Core(TM) i7-4790K MSI Z97 GAMING 7 (MS-7916)  XFX Radeon R9 295X2 HyperX 32GB 
Hard DriveOSMonitorKeyboard
Kingston SSDNow V300 Series (RAID0) Windows 8.1 Pro Samsung ua40hu7000rxzn (40" UHD) Logitech G105 
PowerCaseMouse
EVGA 850B Corsair Carbide Series Black 500R Mid Tower Logitech G502 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Application Programming