开发者

Using filestream within a button click event in ms visual c++

开发者 https://www.devze.com 2023-02-14 07:45 出处:网络
I know tha开发者_如何学运维t you have to include the fstream library in order to use. Let\'s say I have a windows form project in visual c++ named sample_project. And of course that would have a main

I know tha开发者_如何学运维t you have to include the fstream library in order to use. Let's say I have a windows form project in visual c++ named sample_project. And of course that would have a main source file named sample_project.cpp.

I have placed

include <fstream>

on the sample_project.cpp file but calling the filestream functions in the button click event on my form still does not work. This is probably basic stuff that I am missing here but any help would be greatly appreciated.


I can't tell for certain, because you forgot to post the code from your button click event handler where you try to call the filestream functions, but my guess is that you've forgotten to qualify the function calls with the appropriate namespace.

The functions defined in that header file are in the std namespace, so you would have to write:

std::fstream

Or add a using directive to the top of your code file:

using namespace std;

Also, I assume you just had problems with the code formatting feature, but make sure that your include statement actually looks like this, noting the # sign and the lack of space around the angle brackets:

#include <fstream>

Remember that a Windows Forms project targets the .NET Framework, and is designed to facilitate interoperability between native and managed code. If you intended to write pure, unmanaged C++ code, you create a console or Win32 application, instead. And if you don't need the specific functionality provided by fstream.h, you could investigate using the standard file manipulation classes included with the .NET Framework. They're not quite as powerful, but they are more than adequate in the majority of cases, and far simpler to use for a beginning programmer.

0

精彩评论

暂无评论...
验证码 换一张
取 消