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 1938
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
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
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;
aeo3-
Please use code tags around your code, they are [code=cpp] and [/code]
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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: 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,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |