Hello Everybody;
I would like to append a number to set of char, I do not like to use string, because In my project I am using several files.
What I did but there is a problem with it is as follows
1. char filename[30];
2. int x=2;
3. filename="xxxxx ";
But i do not know how to append 2 to filename.
Thanks
8 1953 Savage 1,764
Recognized Expert Top Contributor
Hello Everybody;
I would like to append a number to set of char, I do not like to use string, because In my project I am using several files.
What I did but there is a problem with it is as follows
1. char filename[30];
2. int x=2;
3. filename="xxxxx ";
But i do not know how to append 2 to filename.
Thanks
What's seems to be the most logical way to you?
How would you do it with string?
Savage
What's seems to be the most logical way to you?
How would you do it with string?
Savage
With string we can use a function strcpy, but with character variable it is not available to do this
I mean, I would like to change my filename within a loop
filename1.txt
filname2.txt ...etc
Savage 1,764
Recognized Expert Top Contributor
With string we can use a function strcpy, but with character variable it is not available to do this
I mean, I would like to change my filename within a loop
filename1.txt
filname2.txt ...etc
But you can have two cstrings(you are working in c,right?),one will contain base filename and second it's number converted to char array using itoa.After that you just append second string to the first,and there you have it.
Savage
But you can have two cstrings(you are working in c,right?),one will contain base filename and second it's number converted to char array using itoa.After that you just append second string to the first,and there you have it.
Savage
I was tried to use itoa, but compiler complains, Also, i am using c++ with Cgywin complier
Savage 1,764
Recognized Expert Top Contributor
I was tried to use itoa, but compiler complains, Also, i am using c++ with Cgywin complier
Can you show us that line of code?
Savage
Can you show us that line of code?
Savage
This is the new trial that i am trying to use string but there is many problems so I thought to use char -
string int2string(const int& number)
-
{
-
ostringstream oss;
-
oss << number;
-
return oss.str();
-
}
-
-
-
-
string FILENAME;
-
-
for(int i=0;i<numEco;i++)
-
{
-
FILENAME="inf_h_";
-
FILENAME+=int2string(h);
-
FILENAME.append("_f_");
-
FILENAME+=int2string(f);
-
FILENAME.append("_");
-
FILENAME+=int2string(i);
-
FILENAME.append(".txt");
-
// strcpy(str,FILENAME);
-
EcoArray[i]->Run_Economy();
-
}
-
and here is an attempt but by using char -
int h=5;
-
char filename[30]="inf_"
-
filename=filename+h;
sicarie 4,677
Recognized Expert Moderator Specialist
aeo3-
Please use code tags around your code, they are [code=cpp] and [/code]
Savage 1,764
Recognized Expert Top Contributor
This is the new trial that i am trying to use string but there is many problems so I thought to use char -
string int2string(const int& number)
-
{
-
ostringstream oss;
-
oss << number;
-
return oss.str();
-
}
-
-
-
-
string FILENAME;
-
-
for(int i=0;i<numEco;i++)
-
{
-
FILENAME="inf_h_";
-
FILENAME+=int2string(h);
-
FILENAME.append("_f_");
-
FILENAME+=int2string(f);
-
FILENAME.append("_");
-
FILENAME+=int2string(i);
-
FILENAME.append(".txt");
-
// strcpy(str,FILENAME);
-
EcoArray[i]->Run_Economy();
-
}
-
and here is an attempt but by using char -
int h=5;
-
char filename[30]="inf_"
-
filename=filename+h;
What are the problems with c++ strings?
If you want to use c style strings you cannot use operator+,if you try to use you will get something as :Invalid pointer arithmetic...
If you want to append then use strcat Sign in to post your reply or Sign up for a free account.
Similar topics |
by: tertius |
last post by:
Is there a better way to append certain chars in a string with a
backslash that the example below?
chr = "#$%^&_{}" # special chars to look out for
str = "123 45^ & 00 0_" # string to convert
n = "" # init new string
for i in str:
if i in chr: # if special character in str
n+='\\' # append it with a backslash
n+=i
|
by: JMCN |
last post by:
hi-
i have inherited an access 97 database that keeps track of the loans.
i have been running into referential intergrity problems when i try to
append new loans to table.
first of all is a linked table from another ms
database. when i try to run the append query, i receive an error
message that it cannot append all the records due to key violations to
the . so i looked at all of the relationships and
|
by: David Barger |
last post by:
Greetings,
It appears that an Append Query I run in Access XP is randomly failing
to append a field.
I have payroll data being entered into a payroll database. This data
is exported daily to two csv files. (One for updated data, and the
other for unupdated data.)
The CSV files are attached to my Jobcosting database. After the CSV
|
by: todorov-fkt |
last post by:
Hello
Provided the following code:
string temp = "Short string"; // 12 chars
StringBuilder sb = new StringBuilder();
sb.Append(temp, 0, 30);
How many characters is the string in sb? 12 or is it filled with blanks to
reach 30 chars?
|
by: Two Beards |
last post by:
Hi, I'm new to VB and .net so I may be mising something. I am trying to
dynamically build some SQL by appending to a string. Part of the SQL
comes from an mp3 id tag I have extracted from a file and stored in a
string. I can do all the normal stuff with the string like msgbox and I
can append it to another string but I cannot append to the end of it.
I have tried things like trim and using a string builder but it still
won't work.
Any...
| |
by: pmacdiddie |
last post by:
I have an append query that needs to run every time a line item is
added to a subform. The append writes to a table that is the source
for a pull down box. Problem is that it takes 5 seconds to run. This
makes adding lines to an order too slow for the users. The result of
the query provides real time availabilty, so I really do need this to
work.
The tblJobs has only 10,000 records, tblJobsLineItems has 150,000
records.
|
by: Freddy Coal |
last post by:
Hi, I would like append strings to a binary file, but I don´t understand how
make that.
I try with:
FileOpen(1, Folder_Trabajo & "\Toma_Trazas.FC", OpenMode.Append,
OpenAccess.Write, OpenShare.Default)
FilePut(1, "My string") '<****** ERROR IN THIS LINE ******
FileClose(1)
|
by: thanawala27 |
last post by:
Hi,
I wanted to append a cell of an Excel file.
Basically, the excel file is not taking more than 256 characters for a cell at a time.
So i thought of breaking the varaible into 2. n copying it one by one. But hte 2nd variable needs to be appended to the first variable in the Cell.
I had posted something on related topic sometime back (http://www.thescripts.com/forum/thread682464.html), and i was able to find out that there is some...
|
by: nujcharee |
last post by:
Hi
I have a series of queries, I have a number of temp tables which I use
as templates for my data.
I start with
1. Delete the data in a temp table
2. Use append query to fill the temp table with data
Now, in the temp table, I have a memo field. I append information from
a text column (Oracle DB) into the memofield in the temp table. For
some reason, only the first 255 characters copied across as if it
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |