| | |
Newbie question(open a file)
Thread Solved |
Hi all,
I have just start to work on C++.
I want to open a text file, then write few text there. This is the code I wrote for that.
When I compile it gives the following error.
What's wrong there. Can you guys help me to solve it.
I have just start to work on C++.
I want to open a text file, then write few text there. This is the code I wrote for that.
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <fstream> using namespace std; int main() { ofstream file; file.open ("example.txt"); if(file.is_open()) { file << "Write a text line"; file.close(); } else { file << "Unable to wirte text"; } return 0; }
When I compile it gives the following error.
•
•
•
•
Compiling...
rbf.cpp
Linking...
LIBCD.lib(wincrt0.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function _WinMainCRTStartup
Debug/ReadFile.exe : fatal error LNK1120: 1 unresolved externals
you created a windows program not a console program. The simplest fix to that problem is to start all over again, but this time when you get to the Application Settings window choose Console Application
[edit] what WolfPack wrote -- I didn't see it when I wrote this [/edit]
About the code you posted: If the file failed to open you can't write an error message to it. You probably want to use cout instead of the file handle that failed to open.
[edit] what WolfPack wrote -- I didn't see it when I wrote this [/edit]
About the code you posted: If the file failed to open you can't write an error message to it. You probably want to use cout instead of the file handle that failed to open.
Last edited by Ancient Dragon; Sep 4th, 2007 at 8:26 am.
The most important thing in the Olympic Games is not to win but to take part, just as the most important thing in life is not the triumph but the struggle. The essential thing is not to have conquered but to have fought well.
-Pierre de Coubertin, The Olympic Creed Inspired by Bishop Ethelbert
-Pierre de Coubertin, The Olympic Creed Inspired by Bishop Ethelbert
Ok, Here what I have done.
I used Microsoft Visual Studio .Net 2003.
First click File -> New -> Project
From New Project window, select Visual C++ Project as project type and Win32 Console Project as template.
On the Application Settings, select Console Application and Empty Project.
But I'm fail. What should I do?
I used Microsoft Visual Studio .Net 2003.
First click File -> New -> Project
From New Project window, select Visual C++ Project as project type and Win32 Console Project as template.
On the Application Settings, select Console Application and Empty Project.
But I'm fail. What should I do?
![]() |
Similar Threads
- Doubleclick to open file. (C#)
- Can seem to open my file (C++)
- open a file and divide its data in arrays (C)
- Newbie Question - How to generate a link (PHP)
- Open any file and List. (Visual Basic 4 / 5 / 6)
- Reading and Writing Data to a File (Visual Basic 4 / 5 / 6)
- Cannot open file : a (Windows 95 / 98 / Me)
Other Threads in the C++ Forum
- Previous Thread: Help: Win32 and standard lib functions.
- Next Thread: Compliler errors
Views: 1740 | Replies: 7
| Thread Tools | Search this Thread |
Tag cloud for C++
algorithm array arrays assignment beginner binary c++ c/c++ calculator char class classes client code command compile compiler console constructor conversion convert count delete dll dynamic encryption error file files filestream fstream function functions game givemetehcodez graph gui homework http iamthwee ifstream input int lazy linker list loop loops math matrix member memory multidimensional newbie number object objects opengl operator output parameter pointer pointers problem program programming project qt random read recursion recursive reference server simple sort spoonfeeding string strings struct student studio system template templates text time tree variable vc++ vector video visual visualstudio void win32 window windows winsock wordfrequency






