473,383 Members | 1,818 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,383 software developers and data experts.

Simple string manip question

I'm trying to add a file tpye to the end of a string as I'm doing some
file writing. This code doesn't work, what would be the correct way of
doing this:

ofstream a_file( myString + ".txt", ios::app );

Sorry for the triviality, I've been searching around all morning to no
avail. Thanks, for any help.

Lorn

Jul 23 '05 #1
5 1825
do this:
string a,b;
string bambi = a + b;

fstream a_file;
a_file.open(bambic_str(), ios_base::in | ios_base::out | ios::binary);

Jul 23 '05 #2
thanks, SOS

regards, lorn

Jul 23 '05 #3
Lorn wrote:
I'm trying to add a file tpye to the end of a string as I'm doing some
file writing. This code doesn't work, what would be the correct way of
doing this:

ofstream a_file( myString + ".txt", ios::app );


What is myString? And how does your code "not work" - what error
message do you get?

If myString is a char*, then + doesn't work at all.

If myString is a string, then + will do what you expect and return a string.

But the ofstream constructor requires a char* for the filename
parameter, not a std::string (aarrgghh!). So you need to get a char*
for that temporary string:

(myString+".txt").c_str()

--Phil.
Jul 23 '05 #4
>do this:
string a,b;
string bambi = a + b; fstream a_file;
a_file.open(bambic_str(), ios_base::in | ios_base::out | ios::binary);


here i meant: a_file.open(bambi.c_str(), ios_base::in | ios_base::out |
ios::binary);
(the dot before .c_str() )

Jul 23 '05 #5
It was actually a CString. I ended up doing the code below, which works
fine. Thank you guys for your help.

CString name = "myName"
CString filetype = ".txt";
CString filename = name + filetype;
ofstream a_file ( filename, ios::app );

Jul 23 '05 #6

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

Similar topics

0
by: blupp | last post by:
Hi, I am trying to install the package, but get the following error: cpan> install Date::Manip Running install for module Date::Manip Running make for S/SB/SBECK/DateManip-5.42a.tar.gz LWP...
0
by: marcie | last post by:
I'm writing a program which retrieves data from a 3rd party and inserts it into a sql database. The data provided has timestamps in GMT and I want to insert them with both the GMT time and Central...
51
by: Alan | last post by:
hi all, I want to define a constant length string, say 4 then in a function at some time, I want to set the string to a constant value, say a below is my code but it fails what is the correct...
9
by: Aaron | last post by:
I need some help writing a function that converts "name:john" into "<name>john</name>" it should be compatible with different tags, not just names "name:john"
34
by: Chad | last post by:
Given the following code that achieves no useful purpose: #include <string.h> #include <stdio.h> #include <string.h> int manip(char *str) { size_t len = strlen(str)-1; if(len >= 3) {
4
by: dba_222 | last post by:
Dear Experts, Ok, I hate to ask such a seemingly dumb question, but I've already spent far too much time on this. More that I would care to admit. In Sql server, how do I simply change a...
8
by: rfox | last post by:
Searching the web, there seems to be a myriad of ways to achieve rounded corners on a fixed-width div. I'm looking for suggestions on the simplest, most straight-forward method of achieving this. ...
30
by: galiorenye | last post by:
Hi, Given this code: A** ppA = new A*; A *pA = NULL; for(int i = 0; i < 10; ++i) { pA = ppA; //do something with pA
17
by: Chris M. Thomasson | last post by:
I use the following technique in all of my C++ projects; here is the example code with error checking omitted for brevity: _________________________________________________________________ /*...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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?

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.