473,796 Members | 2,904 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

input and output questions about file

下面程序建立不 宋募,不知道哪 锍龃砹?

只想定义一个fst ream类型来完成 淙胧涑龅墓ぷ.
#include<iostre am>
#include<conio. h>
#include<fstrea m>

using namespace std;

int main()
{
fstream file("a.txt",fs tream::in|fstre am::out|fstream ::app);
string s1,s2;

if(!file) cerr<<"error"<< endl; //why the program have
//error when connecting
up "a.txt"

s1="abcd 1234\n";
file<<s1; //why don't write in a.txt?
file.flush();
file.seekg(0);
file>>s2;
cout<<"s2="<<s2 <<endl;//s2 is empty

file.close();

getch();
return 0;}

the program can run without any error,but the result is:

error

s2=

the program don't create file "a.txt",How do i do?

Feb 24 '07 #1
6 3119
On Feb 24, 10:13 am, "Dic4...@163.co m" <Dic4...@163.co mwrote:
下面程序建立不 宋募,不知道哪 锍龃砹?

只想定义一个fst ream类型来完成 淙胧涑龅墓ぷ.
#include<iostre am>
#include<conio. h>
#include<fstrea m>

using namespace std;
<snip>
the program can run without any error,but the result is:

error

s2=

the program don't create file "a.txt",How do i do?
You go talk to the guys in comp.lang.c++
Just down the hall, second door on the right (just after the koolade
dispenser)

--
Lew
Feb 24 '07 #2
Di*****@163.com wrote:
下面程序建立不 宋募,不知道哪 锍龃砹?

只想定义一个fst ream类型来完成 淙胧涑龅墓ぷ.
下面程序又不是C 语言,你到comp. lang.c++去吧。

The program below is not even in the C language. I suggest you go to
comp.lang.c++

--
Simon.
Feb 24 '07 #3
On 2月24日, 下午11时41分, Simon Biber <n...@ralmin.cc wrote:
Dic4...@163.com wrote:
下面程序建立不 宋募,不知道哪 锍龃砹?
只想定义一个fst ream类型来完成 淙胧涑龅墓ぷ.

下面程序又不是C 语言,你到comp. lang.c++去吧。

The program below is not even in the C language. I suggest you go to
comp.lang.c++

--
Simon.
I see.
Feb 24 '07 #4
Di*****@163.com wrote:
涓嬮潰绋嬪簭寤 绔嬩笉浜嗘枃浠 ,涓嶇煡閬撳摢閲 屽嚭閿欎簡?

鍙兂瀹氫箟涓 涓猣stream绫诲 嬫潵瀹屾垚杈撳 ヨ緭鍑虹殑宸ヤ .
#include<iostre am>
#include<conio. h>
#include<fstrea m>
<iostreamand <fstreamare C++ headers. They are not part of C;
questions involving anything associated with those headers belong in
<news:comp.lang .c++>, not <news:comp.lang .c>.

<conio.his not a standard C or C++ header. Any questions involving
anthing associated with that header should go to an
implementation-specific newgroup, mailing-list, or technical support.
They do not belong here (comp.lang.c) or in comp.lang.c++.
>
using namespace std;
That is a syntax error in C.
Feb 24 '07 #5
On 24 Feb 2007 07:13:08 -0800, in comp.lang.c , "Di*****@163.co m"
<Di*****@163.co mwrote:
>using namespace std;
comp.lang.c++ is down the hall, second left.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Feb 24 '07 #6
"Di*****@163.co m" wrote:
>
.... snip incomprehensibl e ...
>
#include<iostre am>
#include<conio. h>
#include<fstrea m>

using namespace std;

int main()
{
fstream file("a.txt",fs tream::in|fstre am::out|fstream ::app);
string s1,s2;

if(!file) cerr<<"error"<< endl; //why the program have
//error when connecting
up "a.txt"

s1="abcd 1234\n";
file<<s1; //why don't write in a.txt?
file.flush();
file.seekg(0);
file>>s2;
cout<<"s2="<<s2 <<endl;//s2 is empty

file.close();

getch();
return 0;}

the program can run without any error,but the result is:
Don't believe you.

junk.c:1:19: iostream: No such file or directory (ENOENT)
junk.c:2:18: conio.h: No such file or directory (ENOENT)
junk.c:3:18: fstream: No such file or directory (ENOENT)
junk.c:5: parse error before "namespace"
junk.c:5: warning: type defaults to `int' in declaration of `std'
junk.c:5: ISO C forbids data definition with no type or storage
class
junk.c: In function `main':
junk.c:9: `fstream' undeclared (first use in this function)
junk.c:9: (Each undeclared identifier is reported only once
junk.c:9: for each function it appears in.)
junk.c:9: parse error before "file"
junk.c:10: `string' undeclared (first use in this function)
junk.c:12: `file' undeclared (first use in this function)
junk.c:12: `cerr' undeclared (first use in this function)
junk.c:12: `endl' undeclared (first use in this function)
junk.c:12: parse error before '/' token
junk.c:17: `s1' undeclared (first use in this function)
junk.c:17: parse error before '/' token
junk.c:17:24: missing terminating ' character
junk.c:17:24: warning: character constant too long
junk.c:20: `s2' undeclared (first use in this function)
junk.c:21: `cout' undeclared (first use in this function)
junk.c:21: parse error before '/' token
junk.c:25: warning: implicit declaration of function `getch'

c != C++

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net>

Feb 24 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4588
by: slickn_sly | last post by:
For some reason, I'm getting an error. It doesn't seem to be reading my "input.txt" file. I'm trying to read the "input.txt" file which consits of random integers and use insertion sort to sort them in order. Then, i want to have the sorted integers go the file "output.txt" static final int MAX_NUM = 100; public static void main( String args ) throws java.io.IOException {
2
6626
by: sam | last post by:
Hi, I've been buried in xsl and xslt articles for several days now, and am still unsure as to what I need to do... Basically, my vb.net app loads up an XML file from an external source (Input.xml). When the user is setting up the source, they can make changes to it to specify which columns to include for use in my app, they can rename columns, they can mark a column as being of a known datatype (my own custom datatypes, e.g. a Tree). ...
7
7537
by: MM | last post by:
Hi there, How can I change my code (below) so that I use an "input argument" to specify the file name of the input file? For example, if I compile the code and that the application then gets the name "splitdata", then I want to be able to call my application with something like this (datafile.txt will then be the name of the input file): splitdata datafile.txt
1
1845
by: Aalok | last post by:
This is what i want to do. Read a text file as an input and based on that file, Create an outpu text file which saves the contents of the input file in a specifi format in the output file. I know how to read a text file and i can even display the contents o the input file on the prompt. However i am trying to figure out how t save the contents of the input file in a specific manner.
4
6217
by: Carlo Marchesoni | last post by:
I really don't achieve to read a simple 'input.txt' with the following content: J眉rg (Hex: 4a fc 72 67) to an identical 'output.txt' I do the following (and tried with tons of different encodings): private static void WriteFile() { StreamWriter sr = File.CreateText("Output.txt"); try { using (TextReader tr = new StreamReader(new
0
4931
by: srikar | last post by:
Hi all, I am having a problem, when I am compiling the code in 32 bit option on a 64 bit machine using the macro CPPFLAGS= -m32 I am getting the following warnings from the linker . /`../bin/amd64_stat_gnu_02015/WriteFault.o' is incompatible with i386:x86-64 output /usr/bin/ld: warning: i386 architecture of input file `../bin/amd64_stat_gnu_02015/WriteLogic.o' is incompatible with i386:x86-64 output /usr/bin/ld: warning: i386...
5
756
by: Dic4000 | last post by:
下面程序建立不了文件,不知道哪里出错了? 只想定义一个fstream类型来完成输入输出的工作. #include<iostream> #include<conio.h> #include<fstream> using namespace std;
3
6115
by: John Williams | last post by:
I'm writing a stagenography program to experiment with how it works. The algorithm I'm using appears to be producing the correct result...however I'm struggling with the file input. I never learned file input/output very well (I self taught all the programming I know...and my c++ book was not good) and so I'm not sure what's wrong with this. The problem is the function void encodemsg(fstream *img, fstream *msg, fstream *out, char key) ...
1
3615
by: yohan610 | last post by:
i have to read the binary data of a file, then encrypt them according to a supplied algorithm...and then the obtained output has to be written to an output file...everything works ok, and there are no errors... but when i print out the binary data from the input file it seems to be the same whtever the file, and then after encrypting and wirting the data to the output file, the output file has a size of 0KB and nothing in it..pls help as soon...
14
12832
by: =?Utf-8?B?R2lkaQ==?= | last post by:
Hi, In my windows applicationm, i need to excute a batch file. this batch file throws some text and questions to the screen, i need to catch the standard Output, check if it's a question, in case it's a question, i want to popup a messageBox or something, and bring back to the batch file the result (Yes\No question). I know how to excute the batch file and get all the Standard output at the end, but i don't know who can i read it line by...
0
9535
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10201
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7558
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6802
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5454
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4130
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2931
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.