VS 2010 error - cannot open source file “iostream”

当我重新安装了Visual Studio 2010,并将以前的2010 project重新编译时会提示error: cannot open source file “iostream”。我查阅了一些blogs发现Visual Studio 2010第一次用的时候都会出现这个问题。以下是解决方案(copy from an answer in http://stackoverflow.com/questions/4594292/vs-2010-error-cannot-open-file-iostream):

I've run into the same issue on a couple of different machines where there were other versions of VS (2005, 2008) already installed. I ended up also getting all sorts of strange errors.

I found the following trick worked for me, maybe it will work in your case too: - Open a new instance of VS2010 - Create new console application with the def settings. - Try compile: there should be some errors - Open the "Property Manager" - Bring up the Microsoft.Cpp.Win32.user property sheet of the project - Click on VC++ Directories - Click on the "Executable Directories" field. That should display a drop down, click on the drop down and select "Edit". You should see a bunch of inherited values that supposedly contain all the required directories similar to the ones you listed above. Uncheck the "Inherit from parent or project defaults" option. Recheck it and click "Ok".
- Repeat this for the includes, library directories, etc. -Click on "Apply" and "Ok" - Rebuild the project and check if this worked.

I only needed to do this once. After closing VS and creating a new project, I could just compile. Before I discovered this, I manually removed all inherited values and added absolute paths to all the VS and SDK directories. That also worked, but was a lot more work.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这个错误通常是因为编译器找不到 `graphics.h` 头文件而导致的。这个头文件是 Borland Graphics Interface (BGI) 图形库的一部分,这个库通常在 Turbo C++ 和 Borland C++ 中使用。 如果你在 Visual Studio 中使用 Bresenham 算法绘制圆形,可以使用 Windows GDI (Graphics Device Interface) 或者其他图形库,例如 OpenGL 和 DirectX。这些库都可以用于在屏幕上绘制图形,而且在 Windows 平台上都有完整的支持。 下面是一个使用 Windows GDI 绘制圆形的示例代码: ```c++ #include <iostream> #include <windows.h> using namespace std; LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { const char CLASS_NAME[] = "MyWindowClass"; WNDCLASS wc = {}; wc.lpfnWndProc = WindowProc; wc.hInstance = hInstance; wc.lpszClassName = CLASS_NAME; RegisterClass(&wc); HWND hwnd = CreateWindowEx( 0, CLASS_NAME, "My Window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL ); if (hwnd == NULL) { return 0; } ShowWindow(hwnd, nCmdShow); MSG msg = {}; while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return 0; } LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_PAINT: { PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd, &ps); int x0 = ps.rcPaint.right / 2; int y0 = ps.rcPaint.bottom / 2; int r = 100; HPEN hPen = CreatePen(PS_SOLID, 2, RGB(255, 255, 255)); HGDIOBJ hOldPen = SelectObject(hdc, hPen); Ellipse(hdc, x0 - r, y0 - r, x0 + r, y0 + r); SelectObject(hdc, hOldPen); DeleteObject(hPen); EndPaint(hwnd, &ps); } break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd, uMsg, wParam, lParam); } return 0; } ``` 这个程序创建了一个 Windows 窗口,并在窗口中心绘制一个半径为 100 的圆形。在 `WindowProc` 函数中,我们处理 `WM_PAINT` 消息,并使用 `Ellipse` 函数绘制圆形。`BeginPaint` 和 `EndPaint` 函数用于获取和释放绘图设备句柄,而 `CreatePen` 和 `SelectObject` 函数用于创建和选择画笔对象,以便绘制白色的圆形。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值