C++ :: Deprecated Conversion From String Constant To Char
Aug 6, 2013
I have this old c function that takes as an argument a char*. but my app is written in cpp so i used std::string to store my strings. to pass a char * to the function i tried :
Code:
char *input = new char[args.i.length() + 1];
strcpy(input, args.i.c_str()); and then Code: function (input);
and
function ( (char *)input);
But I still get this warning message which i would like to fix:
Warning: deprecated conversion from string constant to "char*" [-Wwrite-strings]
View 7 Replies
ADVERTISEMENT
Jul 15, 2014
I wrote the following code but i got this error: Deprecated conversion from string constant to 'char*':
#include <iostream>
using namespace std;
#include <stdio.h>
#include <windows.h>
#include <winuser.h>
int Save (int key_stroke, char *file);
void Stealth();
[Code] ....
View 3 Replies
View Related
Aug 23, 2013
I have 1 struture:
Code:
struct SetText{
int PosX;
int PosY;
char *Text;
};
And heres how i add the values:
Code:
SetText *x=new SetText;x->PosX=5;
x->PosX=6;
x->Text ="hello mother";
why i receive that warning in: x->Text ="hello mother"; ?
"deprecated conversion from string constant to 'char*' [-Wwrite-strings]"
View 6 Replies
View Related
Jun 7, 2013
I have a question on conversion between char & string. I have cut & pasted the part of the code from my C++ code and my function "decryptPwd" uses C style code with "char" etc.
I need to pass a string (mypwd) somehow to this function after conversion & then compare it to another string (newmypwd).
I tried - "decryptPwd(mypwd.c_str())==newmypwd.c_str()" but it did not work.
..
#include <string>
..
char* decryptPwd(char hash[64]);
main () {
string mypwd;
string newmypwd;
if (decryptPwd(mypwd)==newmypwd)
[Code] ...
View 7 Replies
View Related
Feb 20, 2015
Can distinguish between character constant and string constant giving examples
View 1 Replies
View Related
Oct 23, 2013
I am trying to use libXl to output text from a C++ program to an Excel file. The problem is coming with this library function:
bool writeStr(int row, int col, const wchar_t* value, Format* format = 0)
Writes a string into cell with specified format. If format equals 0 then format is ignored. String is copied internally and can be destroyed after call this method. Returns false if error occurs. Get error info with Book::errorMessage().
If I give input as a string literal like "Hello World" it is displayed correctly. However, if I try to give input as a variable of type const char*, it displays garbage.
Following is my code. MyCompany::company is a QString.
const char* companyName = MyCompany::company.toStdString().c_str();
sheet->writeStr(4, 0, companyName, companyFormat);
View 3 Replies
View Related
Jun 17, 2014
How can you convert int type to const char*
View 2 Replies
View Related
Jul 4, 2014
I have an array of const char's that are randomly selected in a loop from a list and id like to compare every newly selected choice to be tested against all the others to make sure the same choice isn't given more than once, however the names are lengthy and, for example, using:
for (int x = 0; x<10;x++)//initial loop
while ((choice[x]== choice[x-1] || (choice[x] == choice[x-2]) || etc...)
//^given that I have 10 variables
Would be messy and a painful sight. What would a more convinient way to check each choice?
Edit:It should be said that each choice would then be randomized again and then checked again, and that each newly selected choice is then immediantly used after this. It'll also be assumed that not all the choices have been made when this part runs(ergo choice[3] may not exist yet) as it is in a loop
View 1 Replies
View Related
Apr 13, 2013
#include "stdafx.h"
#include "windows.h"
#include "ddeml.h"
#include "stdio.h"
char szApp[] = "EXCEL";
char szTopic[] = "C:Test.xls";
char szCmd1[] = "[APP.MINIMIZE()]";
[Code] ....
View 2 Replies
View Related
Jul 26, 2012
- API Function
TestSend(ref char data, ref int len, char slot);
---------------------------------------------------
Byte[] IccSelect = new Byte[7]{
0x00,
0xA4, // INS
0x04, //1 0x00, //2 0x0E,
0x31,
0x50,
};
Int32 len = 20;
TestSend(ref ??, ref len, '0');//byte array to char conversion
View 1 Replies
View Related
Oct 9, 2014
In this code, i declared a string constant and trying to print the length of string. I know that if i write char a1[7] or char a1[] than it runs and give aggregate output, but in this case it is giving double length of string.
Code:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
}
[code]....
View 5 Replies
View Related
May 22, 2014
I'm writing a small pice of code that takes numbers and convert it to string. So that's what I got
int main() {
char letter;
char letter1;
char letter2;
cin >> letter;
cin >>letter1;
int sum = letter * 128 + letter1;
[Code] ....
Then it asks the user to enter a letter, say 'w' , which it's value is 119
Then enter another letter, say 'o' which value is 111
then it do the equation, which is take the value of the first letter multiple it by 128 then add it to the value of the second letter.
How can I make it does this process in a For loop, or any kind of loop??
Then I have the second part which is the other way around. That is when the user enter a numbers then the code convert these numbers to a string.
251394404 - "d"
1964018 - "rd"
15343 - "ord"
119 - "word"
so what's happening here is the it divide each time by 128. But I can't do that in a code.
View 3 Replies
View Related
Oct 22, 2013
I want a code that can convert floating/double value into string/char array(char arr[]) and also it can be run on Boreland C++ 5.02
Here I've a code but it doesn't show all the numbers. Instead, it's showing in exponential form which I don't want!!
int main() {
char* str = new char[30];
float flt = 2.4567F;
sprintf(str, "%.4g", flt );
cout<<str<<endl; //Exponential form even after 6 digits without decimal
return 0;
}
View 5 Replies
View Related
Jun 3, 2013
How to convert int into string ? I had done conversion string to int.
My code :
/*Convert string into int using stringstream */
#include <iostream>
#include <string>
#include "console.h"
#include <sstream>
using namespace std;
[Code] .....
View 3 Replies
View Related
Nov 22, 2013
I have the following piece of code:
string ss = findNodeValue( str, "Horizon");
cout << "ss is: " << ss << endl;
double dd = atof( ss.c_str());
cout << "dd is: " << dd << endl;
When the value of 'ss' is printed, I find it prints 1.0, but when the value of 'dd' is printed, it prints 1 whereas it is supposed to print 1.0.
View 2 Replies
View Related
Feb 5, 2014
I have a problem in using ATL 7.0 string conversion macros.
My codes looks like this, which uses ATL 3.0 string conversion macros in the past:
Void Myfunc()
{
USES_CONVERSION;
LPSTR lpszA;
LPWSTR lpszW;
If (...) {
CString strText;
If (...) {
If (bUnicode)
[Code]...
But since 3.0 macros do not support large strings, I want to switch to 7.0 macros, but have problems. Based on the [URL]... samples, I should declare CT2A pszA(strText) or CT2W pszW(strText) within the if and else bodies, as below:
Void Myfunc()
{
USES_CONVERSION;
LPSTR lpszA;
LPWSTR lpszW;
If (...) {
[Code]...
However, in such a case, after running to the codes using lpszA or lpszW, both CT2A and CT2W will be destructed so lpszA and lpszW will be invalid. How to solve this problem?
View 2 Replies
View Related
May 10, 2013
I would like to convert a float or double variable into unsigned char variable and back.
float number_float = 23.453f;
unsigned char* number_char = (unsigned char*)malloc(sizeof(float));
number_char = reinterpret_cast<unsigned char*> (&number_float);
float* number_float_0 = reinterpret_cast<float*>(&number_char);
I am not getting the same value back.. why?
View 2 Replies
View Related
May 10, 2013
following code that I'm reading out of the book "The C++ Standard Library".
class C
{
public:
explicit C(const std::string & s); // explicit(!) type conversion from strings.
...
[Code].....
Now I understand that they are saying that an explicit conversion isn't allowed but what I don't understand is what explicit conversion would be happening if there was one allowed.
Specifically I don't understand the const C & elem syntax. How does this work since the collection holds strings. What would be the syntax for how this:
const C & elem
gets strings. I was thinking it was a class reference that someone how converts to a constructor function pointer or something but i'm really confused.
View 4 Replies
View Related
May 27, 2013
I am trying to use fgets to read in a string, but keep getting a "no conversion function from std::string to char" error.
View 2 Replies
View Related
Mar 21, 2015
So, I'm supposed to do : Create a function with unlimited number of arguments, which forms a dynamic string based on the following form (%d, %s, %f, %lf, %c), with the following prototype:
char*create(char*form, ...);
The function is supposed to have the following output:
create("Peter is %d years old and is in %s-%c class.",7,"second",'A');
-> Peter is 7 years old and is in 7-A class.
create("His GPA is %lf.",4.96);
-> His GPA is 4.96.
create("His favourite subject is math!");
-> His favourite subject is math!
I've managed to do the following :
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
char *create(char *form, ...) {
char *res =(char*)calloc(1,1),*pos_int,*pos_float,*pos_str,pos_char,*pos_long;
[Code] ....
The part with %d and %s string was not that hard, but now I'm supposed to convert %f and %lf to string, I've tried using sprintf but I've had no luck so far, another problem is the fact that I've gotta use lists to complete the task. I've been trying to convert float to string for the past 2 hours, but I'm drawing a blank now.
View 4 Replies
View Related
Sep 21, 2014
char intToStr(int a) {
int n, i, j, sign, set;
char r[10], s[10];
if (a[0] == '-')
sign = -1;
if (sign == -1)
[Code] ....
I have doubt at the time of handling of negative numbers at the time of converting to string ....
View 2 Replies
View Related
Dec 20, 2014
I have the codes for such a problem where, to create a program that counts how many times the second string appears on the first string. Yes it counts if you put 1 letter only, but if you put 2, it is an error. As an example. If the first string is Harry Partear, and the second string is ar, it must count as 3. Here's the code:
Code:
#include <iostream>
#include <conio.h>
using namespace std;
int main ()
[Code] ....
View 6 Replies
View Related
Apr 20, 2013
I'm trying to "tokenize" a string using std::string functions, but I stored the text in a char array. When I try to convert it to a string, the string has the first character right but the rest is garbage.
// Get value from ListBox.
char selectedValue[256];
memset(selectedValue, NULL, 256);
SendMessage(GetDlgItem(hWnd, IDC_LB_CURRENTSCRIPT), LB_GETTEXT, selectedIndex, (LPARAM)selectedValue);
// Convert to string.
string val(selectedValue);
[Code] ....
View 3 Replies
View Related
Feb 5, 2013
A string class that finds a char in the string?
View 1 Replies
View Related
Apr 5, 2013
I have this problem that I don't know how to sort out. I have a feeling it's really simple
#include <iostream>
#include <string>
void main () {
char test[10] = "gorilla";
char try = test[1];
cout << try;
}
I get the error:
lab4.cpp:6: error: expected primary-expression before "char"
lab4.cpp:6: error: expected `;' before "char""
View 2 Replies
View Related
Mar 4, 2013
how can I find ASCII value (0..255) of a character char in a string?
I have an array of char:
Code: char myarray[50]; and I need to have ASCII value of character eg myarray[10]. How can I do that?
View 1 Replies
View Related