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

How do I concatenate three strings?

In my function, my main calls a function to save the data. In script-based
languages like
matlab, I can use multiple in strcat. However, in C++ it's not working since
first argument
of strcat must be the destination.

How can I get arround?

main{

.....
fname = "_0100_0211"; // from somewhere
save_messages(......, char fname);
.....
return (0);
}
function save_messages(......, char fname[100])
{
fname = strcat("MSG_INP_", fname, ".DAT");
fp = fopen(fname, "w");
blah blah
fclose(fp);

fname = strcat("MOD_OUT_", fname, ".DAT");
fp = fopen(fname, "w");
blah blah
fclose(fp);
.....
....

}


Jul 24 '06 #1
5 11228
Mr. Ken wrote:
In my function, my main calls a function to save the data. In script-based
languages like
matlab, I can use multiple in strcat. However, in C++ it's not working since
first argument
of strcat must be the destination.

How can I get arround?
Use std::string rather that C style "strings".

You can concatenate strings with the + operator, or by using a stringstream.

--
Ian Collins.
Jul 24 '06 #2

"Mr. Ken" <Mr. Ken@asdfwrote in message
news:44********@news.starhub.net.sg...
In my function, my main calls a function to save the data. In script-based
languages like
matlab, I can use multiple in strcat. However, in C++ it's not working
since
first argument
of strcat must be the destination.

How can I get arround?

main{

....
fname = "_0100_0211"; // from somewhere
save_messages(......, char fname);
....
return (0);
}
function save_messages(......, char fname[100])
{
fname = strcat("MSG_INP_", fname, ".DAT");
fp = fopen(fname, "w");
blah blah
fclose(fp);

fname = strcat("MOD_OUT_", fname, ".DAT");
fp = fopen(fname, "w");
blah blah
fclose(fp);
....
...

}

If you insist in using C style strings, have a look at sprintf() - it should
help you achieve what you want.
Allan
Jul 24 '06 #3

"Allan M. Bruce" <al*****@TAKEAWAYdsl.pipex.comwrote in message
news:B6********************@pipex.net...
>

If you insist in using C style strings, have a look at sprintf() - it
should
help you achieve what you want.
Allan

Thank you, I am using sprintf now.
My primary style is generic C, which I feel is more portable, and my program
inherits
from some old work which is in C.

If I use Dev-C++ 4.9, can I use both C and C++ statements in one file? In
this way, the
old statements continue to work but I can add new ones with simpler C++
statements.

#include <string.h>
#include <string>

Jul 24 '06 #4

"Mr. Ken" <Mr. Ken@asdfwrote in message
news:44********@news.starhub.net.sg...
>
"Allan M. Bruce" <al*****@TAKEAWAYdsl.pipex.comwrote in message
news:B6********************@pipex.net...
>>

If you insist in using C style strings, have a look at sprintf() - it
should
>help you achieve what you want.
Allan


Thank you, I am using sprintf now.
My primary style is generic C, which I feel is more portable, and my
program
inherits
from some old work which is in C.

If I use Dev-C++ 4.9, can I use both C and C++ statements in one file? In
this way, the
old statements continue to work but I can add new ones with simpler C++
statements.

#include <string.h>
#include <string>
Yes it is possible to use C syntax within C++ programs to a large extent.
The official header for C string operations is <cstring>

Allan
Jul 24 '06 #5
Mr. Ken wrote:
If I use Dev-C++ 4.9, can I use both C and C++ statements in one file? In
this way, the old statements continue to work but I can add new ones with
simpler C++ statements.
Well, there are some differences in C and C++, so you might need some tweaks
here and there, but C++ mostly supports C as a subset.

Jul 24 '06 #6

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

Similar topics

30
by: priya | last post by:
Hi How to concatenate two integer Values. Example Program : #include "Port.h" #include "BinaryConversion.h" # include "iostream.h"
3
by: PC Datasheet | last post by:
I have three lines of text I need to concatenate into one "paragraph". The "paragraph" need to look like: Text1 Text2 Text3 where the lines of text are stacked in the "paragraph". When I use...
3
by: Lars Tackmann | last post by:
Hi - I need a function to concatenate a variable number of strings. I have two ideas but cannot deside which way to go. 1) use the "stdarg" macros - if i use these macros it will be easy to step...
13
by: jt | last post by:
I can't seem to find a way to concatenate strings that have nulls within the string. I have a string that I need another string that has nulls in it and what to append the 2nd string, 3 string...
14
by: metamorphiq | last post by:
Hello, I'm a Java programmer, so I'm probably asking a very simple question here, but I have trouble solving it :) I'd like to know how you concatenate multiple (4, in my case) char* in C++,...
2
by: exapplerep | last post by:
I've seen how to use VBA code to concatenate two fields into a third by using an expression in the "After Update" property in fields 1 & 2. field3 = field1 + field2 The above code would go...
5
by: Diego Martins | last post by:
Since C++ (and STL) have many ways to do string concatenation, I want to hear (read) from you how you do to concatenate strings with other strings and other types. The approaches I know are: --...
1
by: avanthika | last post by:
hi, i want to concatenate values of three column in one row for example my data is: Binoy> select * from fpfm_nominies where emp_no='1283L'; EMP_NO NOMINEE -------...
13
by: sinbad | last post by:
hi, how to concatenate a "hash defined" constant value to another "hash defined" constant string. For example #define ABC 100 #define MYSTR "The value of ABC is" Now i need a string that...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.