typecast int to string

From: Venkat (venkat_kp_at_yahoo.com)
Date: 01/07/04


Date: Wed, 7 Jan 2004 19:39:14 +0530

Hi All,

I want to typecast int to std::string how can i do it.

Here is the sample code.

int NewList[500];

//Fill the NewList with integers values.
......
......

//Replace the file contents with new list values at a specified location.

int i=0;
std::string line;
ifstream inFile(sample);//opens a file to read
while (getline (inFile, line) )
 {

  int comma1Pos = line.find(',');
  int comma2Pos = line.find(',', comma1Pos+1);

  int numChars = comma2Pos - comma1Pos - 1;

  line.erase(comma1Pos+1, numChars); //
  line.insert(comma1Pos+1, (std::string)NewList[i]);
i++;
 }
inFile.close();

In the above code the function insert takes 2nd argument as a string so i
was trying to type cast NewList[i] to string.
The complier throws a type cast error saying type cast int to string is not
possible.

Is there any way i can type cast the same.

regards,
Venkat



Relevant Pages

  • Re: typecast int to string
    ... you want to try looking at Boost's lexical cast facility. ... > Here is the sample code. ... > The complier throws a type cast error saying type cast int to string is not ...
    (comp.lang.cpp)
  • RE: dictionary/hash and 1 versus 1
    ... In order to keep things simple, Perl's string operators ... programming language you have to use its idioms or you end up fighting ... type cast the data: a + b ... and cluttered code is harder to understand ...
    (comp.lang.python)
  • Re: typecast int to string
    ... > The complier throws a type cast error saying type cast int to string is not ... std::string toString(unsigned int) {... ... This will make the compiler produce all of the above functions ...
    (comp.lang.cpp)
  • Re: Operationalize orthogonality
    ... empty string respectively being false, ... this sort of overloading of values is utterly ... a string is a string and a boolean is a ... But that won't stop a determined compiler when it finds an implicit type cast to double, a unary plus operation for double, and an implicit type cast back to string: ...
    (comp.databases.theory)
  • Re: Got a nagging listbox questions
    ... The variable type is missing ... The type cast is missing ... You are trying to assign a String to a property expecting a Color object ... You are storing the wrong string. ...
    (microsoft.public.dotnet.languages.vb)