vs2015使用外部工具改变行尾CRLF->LF

来源:互联网 发布:网络咨询医生话术 编辑:程序博客网 时间:2024/05/18 01:04

VS2015不支持addin和宏了,所以只能手动操作:

(如果用unity的C#脚本,建议高级保存设置成CRLF模式,因为VS2015智能格式化代码是CRLF,修改不了设置,每次他智能缩进都需要ctrl+z,才可以去掉CR,但是这样影响了写代码的速度)


工具代码:

#include<windows.h>#include<iostream>#include<fstream>using namespace std;int main(int argc, char* argv[]){    if (argc != 2)    {        cout << "Please specify : dos2unix filename" << endl;        return 0;    }    char ch;    char temp[MAX_PATH] = "\0";    //Open the file for reading in binarymode.    ifstream fp_read(argv[1], ios_base::in \        | ios_base::binary);    sprintf_s(temp, "%s.temp", argv[1]);    //Create a temporary file for writing in the binary mode. This    //file will be created in the same directory as the input file.    ofstream fp_write(temp, ios_base::out \        | ios_base::trunc \        | ios_base::binary);    while (fp_read.eof() != true)    {        fp_read.get(ch);        //Check for CR (carriage return)        if ((int)ch == 0x0D)            continue;        if (!fp_read.eof())fp_write.put(ch);    }    fp_read.close();    fp_write.close();    //Delete the existing input file.    remove(argv[1]);    //Rename the temporary file to the input file.    rename(temp, argv[1]);    //Delete the temporary file.    remove(temp);    return 0;}



编译好后,配置:

工具-->外部工具-->添加:


选择自己的工具路径

参数:$(ItemPath)$(FileName)$(FileExt)

初始目录:$(TargetDir)


这样打开一个文件,点击自己的工具,就自动删除了CR。

原创粉丝点击