读入文件然后每2个字符添加一个标点,我拿下来测试后,发现2003中需要定义ifstream和ofstream,但还是有2个错误莫名其妙,我的分号有啊#include "stdafx.h"
#include <fstream>
typedef basic_ifstream<char, char_traits<char> > ifstream;
typedef basic_ofstream<char, char_traits<char> > ofstream;
using namespace std;int _tmain(int argc, _TCHAR* argv[]){
    ifstream ifile("1.txt");
    ofstream ofile("2.txt");
    char c ;
    while(ifile.get(c))
    {        if(int(c)>0)
            ofile<<c;
        else
        {
            ofile<<c;
            ifile.get(c);
            ofile<<c;
            ofile<<'.';
        }
            
            
    }
        ifile.close();
        ofile.close();
        system("pause");
      
return 0;
}
错误提示:e:\vc\doublechar\doublechar\doublechar.cpp(6) : error C2143: 语法错误 : 缺少“;”(在“<”的前面)

解决方案 »

  1.   


    #include "stdafx.h" 
    #include <fstream> 
    using namespace std; 
    typedef basic_ifstream <char, char_traits <char> > ifstream; 
    typedef basic_ofstream <char, char_traits <char> > ofstream; int _tmain(int argc, _TCHAR* argv[]) { 
        ifstream ifile("1.txt"); 
        ofstream ofile("2.txt"); 
        char c ; 
        while(ifile.get(c)) 
        {         if(int(c)>0) 
                ofile < <c; 
            else 
            { 
                ofile < <c; 
                ifile.get(c); 
                ofile < <c; 
                ofile < <'.'; 
            } 
                
                
        } 
            ifile.close(); 
            ofile.close(); 
            system("pause"); 
          
    return 0; 
      

  2.   

    还是报错e:\vc\doublechar\doublechar\doublechar.cpp(10) : error C2872: “ifstream” : 不明确的符号
            可能是“e:\vc\doublechar\doublechar\doublechar.cpp(4) : std::basic_ifstream<_Elem,_Traits> ifstream”
            with
            [
                _Elem=char,
                _Traits=std::char_traits<char>
            ]
            或      “d:\Visual studio 2003\Vc7\include\iosfwd(485) : std::ifstream”
    e:\vc\doublechar\doublechar\doublechar.cpp(11) : error C2872: “ofstream” : 不明确的符号
            可能是“e:\vc\doublechar\doublechar\doublechar.cpp(5) : std::basic_ofstream<_Elem,_Traits> ofstream”
            with
            [
                _Elem=char,
                _Traits=std::char_traits<char>
            ]
            或      “d:\Visual studio 2003\Vc7\include\iosfwd(486) : std::ofstream”
      

  3.   


    #include<iostream>
    #include <fstream> 
    #include<TCHAR.h>using namespace std; int _tmain(int argc, _TCHAR* argv[]) { 
        ifstream ifile("1.txt"); 
        ofstream ofile("2.txt"); 
        char c ; 
        while(ifile.get(c)) 
        {         if(int(c)>0) 
                ofile <<c; 
            else 
            { 
                ofile <<c; 
                ifile.get(c); 
                ofile <<c; 
                ofile <<'.'; 
            } 
                
                
        } 
            ifile.close(); 
            ofile.close(); 
            system("pause"); 
          
    return 0; 

      

  4.   

    e:\vc\doublechar\doublechar\doublechar.cpp(36) : fatal error C1010: 在查找预编译头指令时遇到意外的文件结尾