typecast int to string
From: Venkat (venkat_kp_at_yahoo.com)
Date: 01/07/04
- Next message: tom_usenet: "Re: possibility to forbid use of "this"?"
- Previous message: Dan Cernat: "Re: What does this code mean?"
- Next in thread: Hendrik Belitz: "Re: typecast int to string"
- Reply: Hendrik Belitz: "Re: typecast int to string"
- Reply: Martijn Lievaart: "Re: typecast int to string"
- Reply: Evan Carew: "Re: typecast int to string"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: tom_usenet: "Re: possibility to forbid use of "this"?"
- Previous message: Dan Cernat: "Re: What does this code mean?"
- Next in thread: Hendrik Belitz: "Re: typecast int to string"
- Reply: Hendrik Belitz: "Re: typecast int to string"
- Reply: Martijn Lievaart: "Re: typecast int to string"
- Reply: Evan Carew: "Re: typecast int to string"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|