Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot

Closed Thread
 
LinkBack Thread Tools Display Modes
Old 10-05-2007, 06:37 PM   #1 (permalink)
Burning Bright
 
anantkhaitan's Avatar
 
Join Date: May 2006
Location: NIT, Bhopal
Posts: 266
Unhappy File handling using GCC/G++

Friends point me where I m wrong.

Code:
Quote:
#include<fstream>
#include<iostream>
int main()
{
ofstream f;
f.open("1.txt");
f.put(65);
std::cout<<"Inserted";
f.close();
return 1;
}
Command for compilation :
Quote:
$ g++ a.cpp -o a
Error message(s):
Quote:
a.cpp: In function ‘int main()’:
a.cpp:5: error: ‘ofstream’ was not declared in this scope
a.cpp:5: error: expected `;' before ‘f’
a.cpp:6: error: ‘f’ was not declared in this scope
__________________
..::Fedora ::.. Freedom + Infinity + Speech
Registered Linux User #447318

GNUger was here.... Grrr....

Maah! Blog
http://brightedges.blogspot.com/
anantkhaitan is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 10-05-2007, 07:32 PM   #2 (permalink)
Alpha Geek
 
sam_1710's Avatar
 
Join Date: May 2006
Location: Bang Bang BANGALORE !!
Posts: 755
Default Re: File handling using GCC/G++

u forgot to give namespace buddy!!!
this code will compile..
Code:
#include<fstream>
#include<iostream>
using namespace std;
int main()
{
ofstream f;
f.open("1.txt");
f.put(65);
std::cout<<"Inserted";
f.close();
return 1;
}
sam_1710 is offline  
Old 10-05-2007, 07:57 PM   #3 (permalink)
1337 |)00|) \m/
 
kaustav_geek's Avatar
 
Join Date: Nov 2005
Location: Cyber Space
Posts: 472
Default Re: File handling using GCC/G++

^^^
Yeah.. Absolutely correct... As per the ANSI C++ standards, the headers are not longer considered as files.. They are referred from namespace std.....Hence, inclusion of
Code:
using namespace std;
is a standard..
Don't forget it.
__________________
My Blog : www.vatsuak.blogspot.com
My DA page : www.burningsilver.deviantart.com

OK..ok..... Ads are bad..
kaustav_geek is offline  
Old 10-05-2007, 09:49 PM   #4 (permalink)
I see right through you.
 
Sykora's Avatar
 
Join Date: Sep 2005
Location: Chennai
Posts: 597
Default Re: File handling using GCC/G++

Once you've used the namespace, the std:: is not necessary.
__________________
I didn't make the world, I only try to live in it.
http://lucentbeing.com
-- Sykora --
Sykora is offline  
Old 10-05-2007, 10:39 PM   #5 (permalink)
Burning Bright
 
anantkhaitan's Avatar
 
Join Date: May 2006
Location: NIT, Bhopal
Posts: 266
Default Re: File handling using GCC/G++

Thanks a million buddies.. I thought it was only for console in/out thats why used std:: before cout.. anyways i successfully compiled my code..
Quote:
#include<fstream>
#include<iostream>
using namespace std;
int main()
{
ofstream f;
f.open("1.txt");
f.put(65);
cout<<"Inserted";
f.close();
return 1;
}
__________________
..::Fedora ::.. Freedom + Infinity + Speech
Registered Linux User #447318

GNUger was here.... Grrr....

Maah! Blog
http://brightedges.blogspot.com/
anantkhaitan is offline  
Old 12-05-2007, 02:34 PM   #6 (permalink)
Burning Bright
 
anantkhaitan's Avatar
 
Join Date: May 2006
Location: NIT, Bhopal
Posts: 266
Default Re: File handling using GCC/G++

Friends I will be really grateful if anyone of u can suggest me alternative to common used conio functions like getch(), gotoxy(), kbhit(), _setcursortype() etc.
__________________
..::Fedora ::.. Freedom + Infinity + Speech
Registered Linux User #447318

GNUger was here.... Grrr....

Maah! Blog
http://brightedges.blogspot.com/
anantkhaitan is offline  
Old 12-05-2007, 10:17 PM   #7 (permalink)
Alpha Geek
 
saurabh.sauron's Avatar
 
Join Date: Jan 2006
Location: Middle Earth
Posts: 503
Default Re: File handling using GCC/G++

for linux, i dont think is required for getch()...anywayz, here is one.

Quote:
system("Pause");
i dont think linux is able to recognize it.
saurabh.sauron is offline  
Old 12-05-2007, 11:33 PM   #8 (permalink)
In The Zone
 
webgenius's Avatar
 
Join Date: Oct 2006
Posts: 384
Default Re: File handling using GCC/G++

Quote:
Originally Posted by anantkhaitan
Friends I will be really grateful if anyone of u can suggest me alternative to common used conio functions like getch(), gotoxy(), kbhit(), _setcursortype() etc.
are you programming under linux? if yes, then you can't use <conio.h> under GCC.
webgenius is offline  
Old 12-05-2007, 11:37 PM   #9 (permalink)
Debian Rocks!
 
freebird's Avatar
 
Join Date: Feb 2007
Location: Coimbattore
Posts: 528
Default Re: File handling using GCC/G++

Linux
------
Anjuta is a good gui ide for gcc,g++ and more.eclipse also there.
but CLI compiling helps learning gcc core isnt it?
__________________
"The day windows users wake up to reality, it will be doomsday for Microsoft."UNIX like OS are more secure.get urself out 4m M$ http://whylinuxisbetter.net http://tinyurl.com/2amjjc http://fsf.org
freebird is offline  
Old 13-05-2007, 10:04 AM   #10 (permalink)
C# Be Sharp !
 
Zeeshan Quireshi's Avatar
 
Join Date: Jun 2006
Location: Toronto
Posts: 1,805
Default Re: File handling using GCC/G++

Quote:
Originally Posted by anantkhaitan
Friends I will be really grateful if anyone of u can suggest me alternative to common used conio functions like getch(), gotoxy(), kbhit(), _setcursortype() etc.
well mate , conio.h is a propreitary header file of Borland Inc , you won't find it bundled with ny oher compiler than borland compilers , so it's better you use Standard C++ n not rely on compiler-specific until it's a must ..

better still i sugget you Program in C# , it's much easier to program in it than C++ n it has a vast library of functons n you will hardly ever need to use ny external library .
__________________
There are 10 types of people in the world: those who understand binary and those who do not.
Zeeshan Quireshi is offline  
Old 13-05-2007, 12:28 PM   #11 (permalink)
1337 |)00|) \m/
 
kaustav_geek's Avatar
 
Join Date: Nov 2005
Location: Cyber Space
Posts: 472
Default Re: File handling using GCC/G++

Quote:
better still i sugget you Program in C# , it's much easier to program in it than C++ n it has a vast library of functons n you will hardly ever need to use ny external library .
C# in Linux ? Is it not proprietary too ? In case it isn't.. I don't think Linux has inherent support for C# , right ?

A side question.... How strong is Python when compared to C++ or C# ?? Give a neutral opinion over it.........
__________________
My Blog : www.vatsuak.blogspot.com
My DA page : www.burningsilver.deviantart.com

OK..ok..... Ads are bad..
kaustav_geek is offline  
Old 13-05-2007, 01:03 PM   #12 (permalink)
C# Be Sharp !
 
Zeeshan Quireshi's Avatar
 
Join Date: Jun 2006
Location: Toronto
Posts: 1,805
Default Re: File handling using GCC/G++

Quote:
Originally Posted by kaustav_geek
C# in Linux ? Is it not proprietary too ? In case it isn't.. I don't think Linux has inherent support for C# , right ?

A side question.... How strong is Python when compared to C++ or C# ?? Give a neutral opinion over it.........
Python is a scripting language and is not meant for heavy duty System Software development ,

whereas C++/C# are for system level application development .
although C# is a lot easier and as powerful as c++ .

python , Perl , etc r very useful when you wanna do simple tasks n automation like extracting links from web-page , or designing phone-cook kinda software .

also C++/C# give much more performance as they r compiled n Python apps r interpreted .
__________________
There are 10 types of people in the world: those who understand binary and those who do not.
Zeeshan Quireshi is offline  
Old 13-05-2007, 01:04 PM   #13 (permalink)
Burning Bright
 
anantkhaitan's Avatar
 
Join Date: May 2006
Location: NIT, Bhopal
Posts: 266
Question Re: File handling using GCC/G++

eh! Friends I should have explained why I need getch() and others..Ok my mistake
Here is my explanation, Take this program for example :
Code:
int main()
{
int i=0;
char a[]="Help Me! ",ch;
do
{
ch=getch();
printf("%c",a[i%9]);
i++;
}while(ch!=27); // 27 means ESC
return 0;
}
Now in this program whatever key u press.. Only "Help me! " string will be displayed.
Help me in writing the same program without getch().

The same is with kbhit() : This function is used a continuous loop iteration until a key is pressed:
Code:
while(!kbhit())
{
<code>
}
now I want a similar thing.
__________________
..::Fedora ::.. Freedom + Infinity + Speech
Registered Linux User #447318

GNUger was here.... Grrr....

Maah! Blog
http://brightedges.blogspot.com/
anantkhaitan is offline  
Old 13-05-2007, 01:35 PM   #14 (permalink)
I see right through you.
 
Sykora's Avatar
 
Join Date: Sep 2005
Location: Chennai
Posts: 597
Default Re: File handling using GCC/G++

Quote:
Originally Posted by kaustav_geek
How strong is Python when compared to C++ or C# ?? Give a neutral opinion over it.........
I'll try to be as neutral as I can

Python lets you do more, and do it faster. By faster, I don't mean that the program itself is faster, but that it is easier to write a program in python because of the ease of the language.

The drawback is of course, that is slower than compiled languages. This is mainly noticeable in number crunching programs and the like.

The reason why I (and most other Python programmers) prefer python is that the faster program development time is a huge compromise over the performance hit. There are many things you can do in Python that would break your mind in C/C++. Not that it's not possible, just that it's very hard.

Sorry for the off-topic.
__________________
I didn't make the world, I only try to live in it.
http://lucentbeing.com
-- Sykora --
Sykora is offline  
Old 13-05-2007, 01:48 PM   #15 (permalink)
Burning Bright
 
anantkhaitan's Avatar
 
Join Date: May 2006
Location: NIT, Bhopal
Posts: 266
Default Re: File handling using GCC/G++

Friends avoid quarrel between different programming languages here .. plz help me solving my problem.
__________________
..::Fedora ::.. Freedom + Infinity + Speech
Registered Linux User #447318

GNUger was here.... Grrr....

Maah! Blog
http://brightedges.blogspot.com/
anantkhaitan is offline  
Old 22-05-2007, 02:25 PM   #16 (permalink)
Burning Bright
 
anantkhaitan's Avatar
 
Join Date: May 2006
Location: NIT, Bhopal
Posts: 266
Default Re: File handling using GCC/G++

So this thread is dying, Guys please help me with my problem..
And if anyone can write the same program in Python which I have written in Post no. 13
__________________
..::Fedora ::.. Freedom + Infinity + Speech
Registered Linux User #447318

GNUger was here.... Grrr....

Maah! Blog
http://brightedges.blogspot.com/
anantkhaitan is offline  
Old 22-05-2007, 04:19 PM   #17 (permalink)
I see right through you.
 
Sykora's Avatar
 
Join Date: Sep 2005
Location: Chennai
Posts: 597
Default Re: File handling using GCC/G++

Code:
>>> s = 'Help me! '
>>> i = 0
>>> while True :
...     try :
...             c = raw_input()
...     except KeyboardInterrupt :
...             break
...     print s[i % 9],
...     i += 1
I tested for Ctrl-C rather than Esc.
__________________
I didn't make the world, I only try to live in it.
http://lucentbeing.com
-- Sykora --
Sykora is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
uTorrent “announce” URL Handling Buffer Overflow goobimama Technology News 14 16-02-2007 11:06 PM
Handling /dev/dsp in C desertwind Open Source 1 04-01-2007 07:32 PM
Change File size in MB instead of GB in properties of a File rachitar QnA (read only) 4 24-11-2005 09:46 AM


All times are GMT +5.5. The time now is 05:35 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2