Thread: trying to use fstreams... specifically input.seekg

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    2

    trying to use fstreams... specifically input.seekg

    Can anyone find anything immediately wrong with this code? I have two problems
    1) It isn't copying properly, it gets hung up on some c's
    2) When I run the program it gets caught in a loop I think because it won't end.

    char outorin[7];

    while (!input.eof()){
    input.get(c);
    if (c == 'c'){
    input.getline(outorin, 7);
    if (0 == strcmp(outorin, "out >>")){
    output << "cout <<";
    }
    if (0 == strcmp(outorin, "in << ")){
    output << "cin >> ";
    }
    else{
    input.seekg(-6,ios::cur);
    }

    }
    output << c;
    if (input.eof()){
    break;
    }
    }

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Try this:
    Code:
    char outorin[7];
    
    while (!input.eof())
    { 
       input.get(c);
       if (c == 'c')
       { 
          input.getline(outorin, 7);
          if (!input)
             input.clear();
          if (0 == strcmp(outorin, "out >>"))
             output << "cout <<"; 
          else if (0 == strcmp(outorin, "in << "))
             output << "cin >> "; 
          else
          {
             output << c; 
             input.seekg(-6,ios::cur); 
          }
       }
       else 
          output << c; 
       if (input.eof())
          break; 
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fstreams
    By Amyaayaa in forum C++ Programming
    Replies: 9
    Last Post: 06-10-2008, 12:00 PM
  2. fstreams
    By Amyaayaa in forum C++ Programming
    Replies: 2
    Last Post: 04-16-2008, 02:08 PM
  3. how do I make fstream's >> work for my class?
    By MathFan in forum C++ Programming
    Replies: 3
    Last Post: 04-25-2005, 12:01 PM
  4. Auto-backup : Makefiles (Eclipse and CDT specifically)
    By Ashes999 in forum C++ Programming
    Replies: 0
    Last Post: 07-07-2003, 04:05 AM
  5. Problems with fstreams.
    By mosdef in forum C++ Programming
    Replies: 7
    Last Post: 06-19-2002, 03:36 PM