LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-04-2005, 03:12 AM   #1
kornerr
Member
 
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893

Rep: Reputation: 35
Problems with ifstream/ofstream


Here's what I have:
Code:
#include<iostream>
#include<fstream>
#include<string>
using namespace std;

int main(int argc, char* argv[]){
    string input=argv[1];
    string output=input+"FILTERED";
    ifstream in(string(input));
    ofstream out(string(output));
    out<<"Hello, it works!!!";
}
Here's an error:
Code:
root@darkstar:/home/cpp# g++ -o filter filter.cpp
filter.cpp: In function `int main(int, char**)':
filter.cpp:11: error: invalid operands of types `std::ofstream
   ()(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
   and `const char[19]' to binary `operator<<'
What should I do?

Thanks.
 
Old 07-04-2005, 10:22 AM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Your using wrong type for ifstream and ofstream

try :
Code:
...
ifstream in(input.c_str());
ofstream out(output.c_str());
...
Also add return 0 at the end of the main() function
as you declared it as int main()

And may I suggest you to not test / make programs as root ?

Last edited by keefaz; 07-04-2005 at 10:24 AM.
 
Old 07-04-2005, 11:31 AM   #3
kornerr
Member
 
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893

Original Poster
Rep: Reputation: 35
Thanks, keefaz, it works!
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
not able to get fd of ofstream using stdio_filebuf Devika Linux - General 0 03-27-2005 11:33 PM
ifstream errur ashirazi Programming 1 02-14-2005 04:35 AM
ofstream and inheritence phoenix7 Programming 1 01-02-2005 02:52 AM
ofstream problem cgifalcon Linux - Software 2 10-19-2003 12:00 PM
what is the equivalent of ofstream & ifstream on network communication? Hano Programming 2 04-19-2002 01:42 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:51 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration