473,395 Members | 2,689 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

input and output questions about file

下面程序建立不了文件,不知道哪里出错了?

只想定义一个fstream类型来完成输入输出的工作.
#include<iostream>
#include<conio.h>
#include<fstream>

using namespace std;

int main()
{
fstream file("a.txt",fstream::in|fstream::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 3089
On Feb 24, 10:13 am, "Dic4...@163.com" <Dic4...@163.comwrote:
下面程序建立不了文件,不知道哪里出错了?

只想定义一个fstream类型来完成输入输出的工作.
#include<iostream>
#include<conio.h>
#include<fstream>

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:
下面程序建立不了文件,不知道哪里出错了?

只想定义一个fstream类型来完成输入输出的工作.
下面程序又不是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.ccwrote:
Dic4...@163.com wrote:
下面程序建立不了文件,不知道哪里出错了?
只想定义一个fstream类型来完成输入输出的工作.

下面程序又不是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<iostream>
#include<conio.h>
#include<fstream>
<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.com"
<Di*****@163.comwrote:
>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.com" wrote:
>
.... snip incomprehensible ...
>
#include<iostream>
#include<conio.h>
#include<fstream>

using namespace std;

int main()
{
fstream file("a.txt",fstream::in|fstream::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
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...
2
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...
7
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...
1
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...
4
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...
0
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 . ...
5
by: Dic4000 | last post by:
下面程序建立不了文件,不知道哪里出错了? 只想定义一个fstream类型来完成输入输出的工作. #include<iostream> #include<conio.h> #include<fstream> using namespace std;
3
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...
1
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...
14
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.