C++ :: Converting Int To Char - Getting Error

May 31, 2013

I am tying to convert an int to a char. Below is an example of the code that I have but I am getting an error('=':left operand must be l-value). I am not seeing a problem with the code.

int num = 5;
char temp[2];
char final[2];
itoa(num, temp, 10);
m_pRes->final = temp;

View 4 Replies


ADVERTISEMENT

C++ :: Converting Int To Char

Feb 20, 2014

Why is this

Code: fFile << (char) (i)p.x, (char) (i)p.y,(char) (i)p.z); not the same as this

Code: printf("%c%c%c", (i)p.x, (i)p.y, (i)p.z);

View 13 Replies View Related

C++ :: Converting Char To Hex

Nov 8, 2014

Having trouble converting char to hex.

according to here [URL] ....
ô in decimal is 147 and print ô using alt 147

and here [URL] ....
ô in dec is 244 but prints ⌠ using alt 244

put on console

char c = ô;
cout << (int)c << endl;

prints -109 and print m using alt -109

I am using alt to test char output. Why I'm getting a negative value? Which of the tables are correct? I have string of char that I want to print in hex. I get a hex string but the hex value don't correspond to any of the two tables on the websites because the console converts special char to negative values.

View 2 Replies View Related

C++ :: Converting String To Char Array

Mar 30, 2014

In this program, I have to ask the user for an employee, then the program will check to see if the file for that employee exist, if it doesnt then it will automatically create the file.

ReadNew function reads the file....check to see if it exist

CreateNew function creates a new file.

In my code I have no problem with the first part of reading file.. and my createnew function works in other programs where I am asking for input of file name to create the file name. However in this code I cannot figure how to automatically pass the input filename from the ReadNew function to the CreateNew function. I can't ask the user to enter the name a second time, so I have to pass the input filename into both functions. Here is my code.

Code:

//Create a file, append to it, and read it.
#include <iostream>
#include <fstream>
#include <string.h>
#include <stdio.h>
using namespace std;
char filename[256];
string n;
string filelist;
void CreateNew(ofstream & FileNew);

[Code]...

View 1 Replies View Related

C++ :: Converting Char Pointer To String

Mar 5, 2013

Here's the code I'm working on:

string* arrayPush(string *array, char **toks){

if(array[sizeofHistory -1].empty()){
//find the next available element
for(int i=0; i < sizeofHistory; i++ ){

[Code] ....

toks is an array of pointers to strings. I need to assign a toks to array[i].

View 10 Replies View Related

C++ :: Typecasting Char Array To Int (Not Converting)

Jun 1, 2014

I am looking for the correct syntax to typecast a character array as an int. So I would be able to do something like this:

char ch[4];
//...Read characters from file into ch or something, etc...
int i = ( int ) &ch;

or

char ch[4];
//...Read characters from file into ch or something, etc...
int i;
strncpy ( ( char* ) &i, ch, 4 )

I want all the 4 characters ( or bytes ) of ch to be classed as an int. So we are taking the 4 bytes of the character array and placing them in 4 bytes of the integer? How would i go about this?

View 2 Replies View Related

C++ :: Converting String To Char And Float

Nov 15, 2013

So I have to convert ("a499.9") into a char and a float while ignoring the a.

I have the string stored in a buffer and found how to get the char, 4. But I don't know how to get 99.9 as a float.

Here is my code so far.

#include <string>
using namespace std;
main() {
buffer = "a499.9";

[Code] ....

My output:

4
0

How to get that double out?

View 7 Replies View Related

C++ :: Converting A String Input To Char?

Feb 8, 2015

I am writing a program that asks the user for their gender. I know that atoi converts arrays into integers, but I need the input from the user in the form of F or M into a char, and return it to the main function to be displayed at the end of the program.

string Employee::getgender(char gen)
{
cout << "Please enter your Gender: " << endl;
//atoi function would go here, what for char?
getline(cin,gen)
return gen;
}

View 1 Replies View Related

C :: Converting Char Array To Int16 Type

Apr 18, 2013

I am trying to convert a char buffer[1024] with raw data to int 16 buffer2[1024] which is supposed to have hex data (0x01, 0x02 kind of format).

Code:
char temp_buffer[1024];
block_size = sizeof(temp_buffer);
num_blocks = sizeof(char);
Status = mount(0, &myfsObject);
if(Status != DAVEApp_SUCCESS)

[Code] .....

I am verifying the data of resultant buffer by creating a new file and writing data to it. The result which i got is:

Code: H uy H uy H uy H uy H uy H uy H uy H uy

View 2 Replies View Related

C++ :: Law Of Cosines Converting To Degrees Error

Feb 17, 2013

I'm trying to find angles A,B,C using law of cosines and I want the answers to be in degrees and the formula to convert the answer to degrees is angle*PI/180. However the answer does not convert to degrees what am I doing wrong?

Code:
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <cmath>
#define PI 3.14
using namespace std;

[Code].....

View 1 Replies View Related

C/C++ :: Error C202 Appearing While Converting To Hex?

Apr 20, 2015

Error C202 appearing while converting .c to .hex?

Error showing for RL=0.

#include <stdio.h>
#include "89c51.h"
#include "Delay.h"
#include "LCD.h"
#include "Serial.h"
#define Buzzer P3_7
#define VTP2_4
#define RFCmdPortP2&0x0f

[Code] .....

Error showing for RL=0 i.e line no.26.

Attached image(s)

View 1 Replies View Related

C# :: SQLException - Error Converting Data Type Varchar To Numeric

Oct 22, 2014

I am writing a simple program to suck in a txt file then pump it into sql.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Data.OleDb;
using System.Data.SqlClient;

[Code] ......

How I can get past this error and get the data into sql? I read a couple articles on .tag but not sure I understand what to do.

View 11 Replies View Related

C/C++ :: Casting Error Char To Int

Apr 30, 2014

I'm writing a small piece of code that increments through a string of numbers. For every 5 numbers a product is produced. However i'm having an issue understanding an error that keeps occurring.

#include <iostream>
#include <string>
#include <cstdlib>

[Code].....

if you look at the code i've got a string with 5 numbers 1-5 for testing. As the loop increments through the string it takes the first 5 characters and converts them to integers and then a product is returned. The issue is that instead of storing the single letter at position J its storing some combination from the string and as a result gives me a huge product. I tried debugging. I checked what the string[j] value was with a simple cout << and it returned the right number. I even returned the char value before it was converted into an integer and it was the right number.

View 3 Replies View Related

C++ :: String To Const Char Error

Jan 15, 2013

I'm currently finishing up an assignment that was half written by my professor. Below in the testGrades section of code there are two errors both are the same message.

Error: no matching function for call to Grades:: Grades(const char [15])

Test Grades

//Purpose: Test program for the class Grades
// Create stu1 Grades object
// Add 5 grades to stu1 - only 3 can be stored in stu1 - other 2 discarded
// Create stu2 Grades object
// Add only 2 grades

#include <iostream>
#include <string>
#include <iomanip>
#include "Grades.h"

using namespace std;

[Code] .....

View 5 Replies View Related

C++ :: Error On Assigning New Char Value From Struct

Feb 17, 2015

Well I tried to assign a new char value from a struct to another char variable but I got the "Cannot convert 'int' to 'char'" error when compiling. I've tried several alternations but I still can't get away with this error.

Here's a section of the code:

javascript:tx('code')
for(int i = 0 ; i < 10 ; i++){
pts[i].dist = sqrt((pts[i].x*pts[i].x)+(pts[i].y*pts[i].y));
}

[Code].....

View 1 Replies View Related

C++ :: Read Text File Char By Char By Using Vector Class

Oct 29, 2014

Code:

cout<<"Enter Filename for input e.g(inp1.txt .... inp10.txt):"<<flush;
cin>>filename;
ifstream inpfile;
inpfile.open(filename,ios::in);
if(inpfile.is_open())

[Code] .....

View 8 Replies View Related

C++ :: Comparing Char Array To Char Always Returns True

Dec 23, 2014

I've made a code to check whether or not a save file has been created correctly, but for some reason it always returns this line: readdata[qa]=='1' as true. in which qa is the counter I use in a for loop and readdata is a character array consisting of 50 characters that are either 0, 1 or 2.

this is the entire code:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

[Code]....

at first is also went wrong at line 22 and also returned that as true, but then I added brackets and it worked.

View 4 Replies View Related

C++ :: Concatenate Two Char Arrays Into Single Char Array?

Sep 29, 2014

I am trying to concatenate two words from a file together. ex: "joe" "bob" into "joe bob". I have provided my function(s) below. I am somehow obtaining the terminal readout below. I have initialized my memory (I have to use dynamic, dont suggest fixing that). I have set up my char arrays (I HAVE TO USE CHAR ARRAYS (c-style string) DONT SUGGEST STRINGS) I know this is a weird way to do this, but it is academic. I am currently stuck. My file will read in to my tempfName and templName and will concatenate correctly into my tempName, but I am unable to correctly get into my (*playerPtr).name.

/* this is my terminal readout
joe bob
<- nothing is put into (*playerPtr).name, why not?
joe bob joe bob
seg fault*/
/****************************************************************/
//This is here to show my struct/playerInit

[Code]....

View 2 Replies View Related

C :: Char Array With A Phrase To Char Word

Nov 28, 2013

I need to do a function that copy every word from a text to a char word. How can i do it?

View 5 Replies View Related

C++ :: How To Convert Char To Const Char

Jun 3, 2013

I have a file which contains a year and the name of an associated file to be read. I need to extract the data in the txt file and perform some calculations.

( year data file)
2004 2004data.txt
2005 2005data.txt
2006 2006data.txt

Here is what I do. I first declare "char yeardata" and then pass "2004data.txt" to it. Then I call yeardata in ifstream to extract the data inside the file "2004data.txt". The problem is that char yeardata is not constant so I cannot pass the file to it. It doesn't work if I change "char yeardata" to "const char yeardata".

Code:
int oldnewcomp_temp(char* lcfile) {
using namespace std;

int year;
char yeardata;

[Code] ....

View 12 Replies View Related

C/C++ :: Getting Header Error C2447 / Can't Find Error Source

Sep 8, 2014

Cannot manage to find the error source when i try running the program, the first part of the program runs just fine its when i try to get the temperature one that i get the error

#include <iostream>
#define pi 3.141592
using namespace std;
int main() {
double r, h; //declare variables for radious and height
double Surfacearea;

[code]....

View 1 Replies View Related

C++ :: Error C2061 / Syntax Error - Identifier (string)

Apr 3, 2013

I've just recently started to learn C++, and I'm encountering some errors I can't seem to figure out.

InventoryItem.h:

Code:
#pragma once
class InventoryItem {
public:
InventoryItem(string name, int amount);
~InventoryItem(void);
string getName(void);
int getAmount(void);

[code].....

Errors:

Code:
1>d:c++consoleapplicationconsoleapplicationinventoryitem.h(6): error C2061: syntax error : identifier 'string'
1>d:c++consoleapplicationconsoleapplicationinventoryitem.h(8): error C2146: syntax error : missing ';' before identifier 'getName'

[Code] .....

View 14 Replies View Related

C++ :: Converting Text To Hex

Jan 3, 2013

From my tests I found the problem to be somewhere in the Mantissa part that converts it to binary.

bool xsDLL GetHexFromSF_IEEE754( void* to, Text from, ui08 tSize ) {
from.UpperCase();
int db = 0, dB = 0, dBEnd = tSize, dBLast = ( tSize - 1u ), dbEnd = dBEnd * 8;
ui08 *data = reinterpret_cast< ui08* >( to );
for ( ; dB >= 0; --dB )
data[ dB ] = 0u;

[Code] ....

Adjustments made, still having problems though. After finding a more useful resource [URL] ..... I got the function looking more like it should but am still having problems...

View 1 Replies View Related

C++ :: Converting One Format To Another?

Apr 7, 2013

I am in a c++ class and my group is having a hard time making this work... It keeps saying that 'fileOne.open' isn't working.

#include <iostream>
#include <string>
#include <fstream>

[Code]....

View 3 Replies View Related

C++ :: Converting CString To Int?

May 16, 2013

I am having problems with converting a CString to an int and than doing checks on the int to see if it is in a particualr range.Below is what I am doing.

CString numstr = "28"
int num = atoi(numstr);
BOOL valid = TRUE;
if(num < -32,768 {
valid = FALSE;
}

For some reason when running the above code the if statement is executed but it should not be becasue 28 is not less than -32,768. Why this is happening, I am not seeing the reason for this at all!! The num variable is being assigned the correct value.

View 5 Replies View Related

C++ :: Converting Strings In Application

Jun 8, 2014

I am having trouble converting strings in my application.

This is the code that is eventually getting called, the first parameter takes a LPCWSTR

Code:
hr = m_pGraph->RenderFile(m_filePath, NULL); // takes LPCWSTR This is where the trouble begins.

The compiler shows that sResult is proper but after I try to convert a std::string to a wchar it prints garbage

Code: const wchar_t* m_filePath = (wchar_t *) oDb->GetNext().c_str();

Code:
std::string CSqlLiteDatabase::GetNext() {
sqlite3_stmt *oStmt = nullptr;
std::string sql = "SELECT path || filename FROM table WHERE id = 1";
char message[255];

[Code] ....

View 6 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved