LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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 11-10-2003, 10:47 AM   #1
veilig
LQ Newbie
 
Registered: Oct 2003
Posts: 8

Rep: Reputation: 0
opening files with strings for file names


alright, I have 2 strings, I appended the second string the first string and now I want open a file which is the first strings name

s1 = myfile.
s2 = 2

s1+=s2
s1 is now myfile.2

how can I use s1 to open that file?

when I type:
fstream Fin( s1, ios::in );

I'm getting errors that I can't do this with the string as the file name.

any ideas?
 
Old 11-10-2003, 10:54 AM   #2
LogicG8
Member
 
Registered: Jun 2003
Location: Long Island, NY
Distribution: Gentoo Unstable (what a misnomer)
Posts: 380

Rep: Reputation: 30
Well you are using the string library correct?

fstream I believe expects a character array.
try the s1.c_str() method

Last edited by LogicG8; 11-10-2003 at 10:56 AM.
 
Old 11-10-2003, 11:05 AM   #3
veilig
LQ Newbie
 
Registered: Oct 2003
Posts: 8

Original Poster
Rep: Reputation: 0
yeah I am using the string library,

I tried using

fstream Fin( s1.c_str(), ios::in );

like you suggested...and it compiled, but my
if ( ! Fin )...

error checking, get spitting out my error message, so it seems like it's still not opening?
 
Old 11-10-2003, 11:05 AM   #4
veilig
LQ Newbie
 
Registered: Oct 2003
Posts: 8

Original Poster
Rep: Reputation: 0
got it to work, thanks
 
Old 11-10-2003, 11:19 AM   #5
LogicG8
Member
 
Registered: Jun 2003
Location: Long Island, NY
Distribution: Gentoo Unstable (what a misnomer)
Posts: 380

Rep: Reputation: 30
Glad you got it to work,
but next time you are having a
problem I have some advice

Put more detail in the post
like what language, and libraries you are using.
variable declarations are also helpful.
My advice was just a guess at what could be wrong.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
opening linux file system files in windows 95?? timefortea General 6 08-26-2005 01:28 PM
copying files and give new unique names to each file by using xargs command gnim66 Programming 6 06-22-2005 08:29 PM
SAMBA: display of share names is OK but files names are wrong superandrzej Linux - Software 5 02-02-2004 09:14 AM
Searching files for strings tmoorman Linux - Software 4 01-08-2004 01:46 PM
concatenating strings to open files veilig Programming 1 11-10-2003 05:36 PM


All times are GMT -5. The time now is 06:38 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration