import os
import shutil
#-*- coding:cp936 -*-
import codecs
from sys import argv

def replace_all_files(path):
cnt = 0
for root, dirs, files in os.walk(path):
for name in files:
if name.endswith(".cpp"):
f = codecs.open(os.path.join(root, name), "rb+")
text = f.read()
text1 = text
if text.find("\"stdafx.h\"")<0:
key = "#include \"stdafx.h\"\r\n"
if text[:3]==codecs.BOM_UTF8:
text1 = "%s%s%s" % (codecs.BOM_UTF8, key, text[3:])
else:
text1 = "%s%s" % (key, text)
f.seek(0)
f.truncate()
f.write(text1)
cnt = cnt+1
print "[%d] relpace File: " %cnt + os.path.join(root, name)
f.close()

if __name__ == "__main__":
try:
replace_all_files(argv[1])
except Exception, e:
print e.message

python 在头文件添加 #include \"stdafx.h\"\r\n的更多相关文章

  1. fatal error C1010: 在查找预编译头时遇到意外的文件结尾。是否忘记了向源中添加“#include "StdAfx.h"”? 解决方法

    错误描述: fatal error C1010: 在查找预编译头时遇到意外的文件结尾.是否忘记了向源中添加“#include "StdAfx.h"”? 错误分析:     此错误发 ...

  2. 在查找预编译头时遇到意外的文件结尾。是否忘记了向源中添加“#include "StdAfx.h"”?

    在查找预编译头时遇到意外的文件结尾.是否忘记了向源中添加“#include "StdAfx.h"”? 右键选择该文件.cpp格式的->属性->预编译头,→ 不使用预编译 ...

  3. 错误描述:fatal error C1010: 在查找预编译头时遇到意外的文件结尾。是否忘记了向源中添加“#include "stdafx.h"”?(转)

    错误分析: 此错误发生的原因是编译器在寻找预编译指示头文件(默认#include "stdafx.h")时,文件未预期结束.没有找到预编译指示信息的头文件"stdafx. ...

  4. VS2010编译错误:是否忘记了向源中添加“#include "stdafx.h

    VS2010编译错误:是否忘记了向源中添加“#include "stdafx.h 编译提示:fatal error C1010: 在查找预编译头时遇到意外的文件结尾.是否忘记了向源中添加“# ...

  5. 是否忘记了向源中添加“#include "StdAfx.h"”?

    错误分析 此错误发生的原因是编译器在寻找预编译指示头文件(默认#include "stdafx.h")时,文件未预期结束.没有找到预编译指示信息的头文件"stdafx.h ...

  6. twincat3新建cpp提示"在查找预编译头时遇到意外的文件结尾。是否忘记了向源中添加“#include "stdafx.h"

    自己之前在windows下面写过一些c++的函数,想在倍福工控机上直接使用,发现添加了.cpp和.h文件后无法完成编译,会提示 在查找预编译头时遇到意外的文件结尾.是否忘记了向源中添加“#includ ...

  7. [C++]在查找预编译头时遇到意外的文件结尾。是否忘记了向源中添加“#include StdAfx.h”

    问题现象:在写好的.cpp文件后,编译报错.提示"你建立的工程使用了预编译功能, cpp最前边要留一行这样的内容:#include "StdAfx.h"问题原因:网上说是 ...

  8. C++---使用VS在C++编程中出现 fatal error C1010: 在查找预编译头时遇到意外的文件结尾。是否忘记了向源中添加“#include "stdafx.h"”?

    啦啦啦,好久没写博客啦... 对于C++初学者来说适应一个新的编译器还是需要蛮长一段时间的,现在我就给你们说说标题所说的这个问题吧... 第一步:菜单--〉项目--〉设置,出现“项目设置”对话框,左边 ...

  9. vc编程中出现 fatal error C1010: 在查找预编译头时遇到意外的文件结尾。是否忘记了向源中添加“#include "stdafx.h"”?

    解决办法菜单--〉项目--〉设置,出现“项目设置”对话框,左边展开项目,在“源文件”中找到出错的文件,然后在右边选择“C/C++”属性 页,在Category下拉框中选择“Precompiled He ...

随机推荐

  1. Linux的进程/线程通信方式总结(转)

    Linux系统中的进程通信方式主要以下几种: 同一主机上的进程通信方式 * UNIX进程间通信方式: 包括管道(PIPE), 有名管道(FIFO), 和信号(Signal) * System V进程通 ...

  2. TensorFlow学习笔记(二)深层神经网络

    一.深度学习与深层神经网络 深层神经网络是实现“多层非线性变换”的一种方法. 深层神经网络有两个非常重要的特性:深层和非线性. 1.1线性模型的局限性 线性模型:y =wx+b 线性模型的最大特点就是 ...

  3. 吴超老师课程--Hbase介绍和伪分布式安装

    1.HBase(NoSQL)的数据模型1.1 表(table),是存储管理数据的.1.2 行键(row key),类似于MySQL中的主键.     行键是HBase表天然自带的.1.3 列族(col ...

  4. mysql双向主从同步

    双向主从同步 双方互相主从同步配置 然后再my.cnf中加上如下配置 [mysqld]master1:auto_increment_increment = 2 //自增ID的间隔,如1 3 5间隔为2 ...

  5. 连接postgresql

    # psycopg2 engine=create_engine('postgresql+psycopg2://scott:tiger@localhost/mydatabase')#  python 连 ...

  6. s5_day2作业

    # 1:编写for循环,利用索引遍历出每一个字符 # msg = 'hello egon 666' # for i in range(len(msg)): # print(i,msg[i]) # 2: ...

  7. PHP实现文件下载断点续传

    <?php /* * PHP下载断点续传 * from:php100 */ function dl_file_resume($file){ //检测文件是否存在 if (!is_file($fi ...

  8. javascript DOM dindow.docunment对象

    一.找到元素: docunment.getElementById("id"):根据id找,最多找一个:    var a =docunment.getElementById(&qu ...

  9. Windows netstat 查看端口、进程占用(转)

    本文转自:http://ywsm.iteye.com/blog/510670 目标:在Windows环境下,用netstat命令查看某个端口号是否占用,为哪个进程所占用. 操作:操作分为两步: 1)查 ...

  10. 笔记——Springboot response、ServletOutputStream、图形验证码显示慢

    今天遇到一个图形验证码加载很慢的问题,大概耗时有200~500毫秒左右. 根据追踪,图形验证码图片生成耗时0~1毫秒,而response.getOutputStream.write()将图片写入前台页 ...