VS2015找不到stdio.h或new.h的Bug修复

本文详细介绍了在使用Visual Studio 2015时遇到的头文件路径问题,以及如何解决。通过修改特定的MSBuild文件,可以正确配置头文件路径,避免因文件迁移导致的缺失问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

    今天尝试安装了VS2015,发现微软还是没有处理好一台计算机安装多个VS版本时环境配置问题。无论是建立Console控制台程序还是MFC程序,都提示缺少"stdio.h"或"new.h"头文件。VS工程默认的包含路径C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include下的确没有这些头文件,那么应该怎么办呢,难道需要手动从别处拷贝缺少的文件吗?后来搜索了一下发现,微软悄悄将这几个头文件挪到了C:\Program Files (x86)\Windows Kits\10\Include\中了。


VS2012找不到SDKDDKVer.h的Bug修复

    此前写过一篇关于VS2012路径设置的类似文章,VS2015的解决方法还是类似:打开C:\Users\me>\AppData\Local\Microsoft\MSBuild\v4.0\Microsoft.Cpp.Win32.user.props 文件,在该文件中添加分别向<IncludePath>字段添加$(UniversalCRT_IncludePath)和向<LibraryPath>中添加$(UniversalCRT_LibraryPath_x86)。应网友要求将修改后的Microsoft.Cpp.Win32.user.props文件贴在下面供参考:


<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <IncludePath>$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSdkDir)include;$(WindowsSDK_IncludePath);$(UniversalCRT_IncludePath);$(FrameworkSDKDir)\include</IncludePath>
    <LibraryPath>$(VCInstallDir)lib;$(VCInstallDir)atlmfc\lib;$(WindowsSdkDir)lib;$(WindowsSDK_LibraryPath_x86);$(UniversalCRT_LibraryPath_x86);$(FrameworkSDKDir)\lib</LibraryPath>
  </PropertyGroup>
</Project>

#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <sys/wait.h> #include <sys/types.h> #include <signal.h> #define MAX_INPUT_SIZE 1024 #define MAX_ARGS 64 void execute_command(char **args); /* 执行命令 */ int main() { char input[MAX_INPUT_SIZE] = {0}; /* 存储用户输入缓冲区 */ char *args[MAX_ARGS] = {NULL}; /* 命令参数 */ char *token = NULL; /* 分割字符串 */ int arg_count = 0; /* 参数计数器 */ while (1) { printf("myshell > "); fflush(stdout); /* 获取输入, 处理 EOF */ if (fgets(input, sizeof(input), stdin) == NULL) { break; } /* 移除换行符 */ input[strcspn(input, "\n")] = '\0'; /* 处理 exit 命令 */ if (strcmp(input, "exit") == 0) { printf("Exiting shell...\n"); break; } /* 解析命令和参数 */ token = strtok(input, " "); while (token != NULL && arg_count < MAX_ARGS - 1) { args[arg_count++] = token; token = strtok(NULL, " "); } args[arg_count] = NULL; /* 执行命令 */ execute_command(args); } return 0; } /* 执行命令函数 */ void execute_command(char **args) { /* 检查是否为内置命令 */ if (strcmp(args[0], "stop") == 0) { printf("Error: 'stop' is not a command. It should appear in program output.\n"); return; } pid_t pid = 0; int pipefd[2] = {0}; if (pipe(pipefd) == -1) { perror("pipe"); exit(EXIT_FAILURE); } pid = fork(); if (pid == -1) { perror("fork"); exit(EXIT_FAILURE); } else if (pid == 0)/* 子进程 */ { /* 关闭读取端 */ close(pipefd[0]); /* 重定向输出到管道 */ dup2(pipefd[1], STDOUT_FILENO); close(pipefd[1]); /* 执行命令 */ execvp(args[0], args); /* 执行失败 */ fprintf(stderr, "myshell: %s: command not found\n", args[0]); exit(EXIT_FAILURE); } else /* 父进程 */ { close(pipefd[1]); /* 关闭写入端 */ char buffer[MAX_INPUT_SIZE] = {0}; /* 输出缓冲区 */ ssize_t bytes_read = 0; /* 读取字节数 */ ssize_t total_printed = 0; /* 已打印字节数 */ char *stop_pos = strstr(buffer, "stop"); /* 检测输出中是否包含 stop */ /* 读取子进程输出 */ while ((bytes_read = read(pipefd[0], buffer, sizeof(buffer)-1)) > 0) { /* 确保字符串终止 */ buffer[bytes_read] = '\0'; /* 检测输出中是否包含 stop */ if (stop_pos) { /* 1、打印 stop 之前的内容 */ size_t keep_len = stop_pos - buffer; if (keep_len > 0) { printf("%.*s", (int)keep_len, buffer); fflush(stdout); } /* 2、打印stop本身 */ printf("stop"); fflush(stdout); /* 3、终止子进程并打印消息 */ kill(pid, SIGTERM); printf("\nReceived 'stop' in output. Terminating child process.\n"); fflush(stdout); /* 跳过后续处理 */ continue; } else /* 未检测到 stop 时正常打印输出 */ { printf("%s", buffer); fflush(stdout); } } close(pipefd[0]); /* 关闭读取端 */ waitpid(pid, NULL, 0); /* 等待子进程结束 */ } } 这是我的主要功能程序 #include <stdio.h> int main() { for (int i = 0; i < 5; i++) { printf("count: %d\n", i); if (i == 3) { printf("stop"); } } printf("This line should not be printed.\n"); return 0; } 这是我的测试程序 现在运行了./main后,输入以下内容: myshell > ./te myshell: ./te: command not found myshell > ./test count: 0 count: 1 count: 2 count: 3 stop Received 'stop' in output. Terminating child process. myshell > cat test.c cat: cat: No such file or directory cat: cat: No such file or directory #include <stdio.h> int main() { for (int i = 0; i < 5; i++) { printf("count: %d\n", i); if (i == 3) { printf("stop Received 'stop' in output. Terminating child process. myshell > 为什么会输出两个cat再输出test.c中的内容
最新发布
08-08
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include <stdlib.h> #include <string.h> typedef struct user { char name[20]; char password[20]; char phone[12]; struct user* next; }user; user* head = NULL; //从文件录入链表(加载数据) void load_from_file() { FILE* fp = fopen("user.date", "r"); if (!fp) { return ; } char name[20]; char password[20]; char phone[12]; while (fscanf(fp, "%19s %19s %11s %d", name, password, phone) == 3) { user*n= (struct user*)malloc(sizeof(user)); strcpy(n->name, name); strcpy(n->password, password); strcpy(n->phone, phone); n->next = head; head = n; } fclose(fp); } //新用户注册 void register_user() { user* new_user = (user*)malloc(sizeof(user)); printf("请输入用户名\n"); scanf("%s", new_user->name); user* current = head; while (current) { if (strcmp(current->name, new_user->name) == 0) { printf("用户名已存在!\n"); free(new_user); return; } current = current->next; } printf("请输入密码:\n"); scanf("%19s", new_user->password); printf("请输入手机号:\n"); scanf("%11s", new_user->phone); new_user->next = head; head = new_user; printf("注册完毕!\n"); } //老用户登录 int loginuser() { char name_temp[20]; char password_temp[20]; char phone_temp[12]; printf("是否为管理员?\n"); int choice = 0; printf("1.是\n2.不是\n"); scanf("%d", &choice); printf("用户名:"); scanf("%19s", name_temp); printf("密码:"); scanf("%19s", password_temp); user* current = head; while (current) { if (strcmp(current->name, name_temp) == 0&&strcmp(current->password,password_temp)==0) { return 1; } current = current->next; } return 0; } //保存链表进文件 void save_to_file() { FILE* fp = fopen("user.date", "w"); if (!fp) { printf("数据保存失败!\n"); } user* current = head; while (current) { fprintf(fp, "%s %s %s\n",current->name,current->password,current->phone); current = current->next; } fclose(fp); } //释放内存 void free_list() { user* current = head; while (current) { user* temp = current; current = current->next; free(temp); } head = NULL; } int main() { load_from_file(); int choice = -1; do { printf("\n1.注册\n2.登录\n3.退出\n请选择:"); scanf("%d", &choice); switch (choice) { case 1: register_user(); break; case 2: if (loginuser()) printf("登录成功!\n"); else printf("用户名者密码错误\n"); break; case 3: printf("正在退出.......\n"); choice = 3; break; default: printf("无效输入!\n"); } } while (choice != 3); save_to_file(); free_list(); return 0; }
03-11
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值