Thread: Write the .txt "filename" into a file.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    385

    Write the .txt "filename" into a file.

    I am trying to put the filename that I am reading from to the file using this code:
    The file is named ABC and this is what I want to write to the file: "file2".

    I am trying to type in << myfile << but nothing is written to the file.
    I want it to recognice what is written in the paratheses after the declaration of myfile. Is this possible in any way ?

    Code:
    #include "stdafx.h"
    #include <iostream>
    #include <fstream>
    #include <sstream> 
    #include <string>  
    
    using namespace std;
    
    int main () 
    
    { 
    	std::string Date;
    	int Time = 0;
    	char Comma;
    	
    	ofstream Test;
    	Test.open ("file2.txt");
    	ifstream myfile ("ABC.txt");
    
    	getline(myfile, Date, ','); 
    	myfile >> Time;		        // 2111
    	myfile >> Comma;
    
    	if (Time == 2100)            
    	{
    	Test << myfile << Time <<"\n";    
    	}
    
            return 0;
    }
    Last edited by Coding; 01-06-2008 at 01:23 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  2. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  3. Problems passing a file pointer to functions
    By smitchell in forum C Programming
    Replies: 4
    Last Post: 09-30-2008, 02:29 PM
  4. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  5. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 10:51 PM