-
AudioDroid
c++ string boost stringstream csv
Possible Duplicates:Dont print space after last numberPrinting lists with commas C++ #include <vector> #include <iostream> #include <sstream> #include <boost/foreach.hpp> using namespace std;int main() {vector<int> VecInts;VecInts.push_back(1);VecInts.push_back(2);VecInts.push_back(3);VecInts.push_back(4);VecInts.push_back(5);stringstream ss;BOOST_FOREACH(int i, VecInts){ss << i << “,”;}cout << ss.str();return 0; }This prints out: 1,2,3,4,5, Howev
-
John Dibling
c++ stl vector stringstream
I have a vector<char> of data which I want to write into std::stringstream. I tried:my_ss.write(vector.data(), vector.size());…but it seems to put nothing into my_ss which I declared as follows:std::stringstream my_ss( std::stringstream::binary); Why write is not working (app does not crash and compiles with 0 errors, 0 warnings)?
-
DmitryR
c++ json stringstream bada
bada crashed on stringstream read.json::Object objDocument = d(); std::stringstream stream; json::Writer::Write(objDocument, stream); json::Object objDocument2; json::Reader::Read(objDocument2, stream); // <=== crashor like this:std::string *requestString = new std::string(data); AppLog(requestString->c_str()); // <=== contains correct data std::stringstream stream; stream << *requestString; const char *ddd = stream.str().c_str(); AppLog(ddd); // <==== contains random dataHow c
-
Ferrard
c++ recursion segmentation-fault stringstream
#include <sstream> #include <string>using namespace std;void fRec(int i) {if (i == 0) {return;}fRec(i – 1);ostringstream s; }int main(int argc, char *argv[]) {fRec(50000);return 0; }When run, this produces:Segmentation fault (core dumped)Backtrace from gdb:#0 0x000000000040064f in fRec (i=<error reading variable: Cannot access memory at address 0x7fffc75a6f5c>) at strstr.cpp:6 #1 0x000000000040066e in fRec (i=28182) at strstr.cpp:11 #2 0x000000000040066e in fRec (i=28183) at
-
JBL
c++ stringstream
So, I’m trying to use a stringstream in my program, in order to get some formatted string (esp. because I need to convert numbers to string).The thing is, my program crashes, and when I debug it with Visual Studio, in my Spy window, I see that my stringstream’s string buffer yields (when trying to add “Framerate” to it): “FramerateÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍýýýý««««««««îþîþ”Code :std::stringstream s; s << “Framerate”;My code then will crash the moment I try to get the associated string… I ca
-
johnkavanagh
crash stringstream codegear rtl
I’m using Borland Codegear 2007 C++ compiler.I have a crash of my program when I use std::stringstream in my functions.It’s enough to declare a local variable in a function std::stringstream sLoc; that program crashesI verify that the problem can be solved by checking “Linker/Dynamic RTL” optionIs this the only way?I’d like compile the application without Dynamic RTL option. Is it possible compile RTL? Is this a solution? Is there a compiler-patch?
-
Caesar
c++ stringstream
Given data format as “int,int,…,int,string,int”, is it possible to use stringstream (only) to properly decode the fields?[Code]int main(int c, char** v) {std::string line = “0,1,2,3,4,5,CT_O,6”;char delimiter[7];int id, ag, lid, cid, fid, did, j = -12345;char dcontact[4]; // <- The size of <string-field> is known and fixedstd::stringstream ssline(line);ssline >> id >> delimiter[0]>> ag >> delimiter[1]>> lid >> delimiter[2]>> cid >> delim
-
Marian
c++ string stdvector stringstream
I have a class with parse(int argc, char* argv[]) function which I have to use to set a desired state of an object. I’m taking the parameters from the gui using stringstream and then I’m trying to convert them to char** to pass them to the function. Here’s what I’ve got:std::stringstream sstream;sstream << “-clip” << ” ” << min_x_entry.get_text()<< ” ” << max_x_entry.get_text(); // etc.std::cout << sstream.str(); // All looks good herestd::vector<std::st
-
Caesar
c++ string stringstream
I am having some trouble with a simple function that tries to convert integers to a string. Here is the code:string Problem::indexB(int i, int j, int k){ stringstream ss;if(i < 10)ss << “00”;else if(i<100)ss << “0”;ss << i;if(j < 10)ss << “00”;else if(j<100)ss << “0”;ss << j;if(k < 10)ss << “00”;else if(k<100)ss << “0”;ss << k;return ss.str(); }The function works fine, but when a make multiple calls it gives me a segmenta
-
Steve Folly
c++ iostream stringstream
Consider this program:#include <iostream> #include <string> #include <sstream> #include <cassert>int main() {std::istringstream stream( “-1” );unsigned short n = 0;stream >> n;assert( stream.fail() && n == 0 );std::cout << “can’t convert -1 to unsigned short” << std::endl;return 0; }I tried this on gcc (version 4.0.1 Apple Inc. build 5490) on OS X 10.5.6 and the assertion is true; it fails to convert -1 to an unsigned short.In Visual Studio 2005
-
0x499602D2
c++ arrays memory-management stringstream istringstream
Can anyone explain how the following code is working and does not crash the application?int main() {char *tempStr = new char[5];tempStr[0] = ‘\0’;string stemp = “helloworld”;stringstream sstream;sstream.str(stemp);cout << “len before = ” << strlen(tempStr);sstream >> tempStr;cout << “len after = ” << strlen(tempStr) << endl;cout << tempStr << endl;delete[] tempStr;return 1; }I am getting the output as len before = 0 len after = 10 helloworldDid str
-
adriano abrantes
c++ type-conversion stringstream
I have tried to solve this with previously answered questions like Conversion from string to float changes the number but I have not been successful. In my code I take a string full of ‘ ‘ characters and convert it to float using stringstream. It worked fine (returned me a zero valued float) until I performed another conversion right after that. When a conversion is executed afterwards, the value stored in the float previously converted is not zero, but 4.57048e-41. I hope the following code ex
-
EdgeLuxe
c++ string insert stringstream
so I am trying to insert the character, which i got from a string, to another string. Here I my actions:1. I want to use simple:someString.insert(somePosition, myChar);2. I got an error, because insert requires(in my case) char* or string 3. I am converting char to char* via stringstream:stringstream conversion; char* myCharInsert; conversion << myChar //That is actually someAnotherString.at(someOtherPosition) if that matters; conversion >> myCharInsert; someString.insert(somePositio
-
user1972060
c++ string stl stringstream
I have a vector:vector<stringstream*> ssv; for (int i = 0; i < cIter; i++) {ssv.push_back(new std::stringstream); }How can I put in elements of vector ssv strings?I try:string s1 = “easfef” + ‘\n’; int i = 0; *ssv[i] << s1 << ‘\n’;But it give me an empty string: string sdf = ssv[i]->str();How can I do it?Thanks for helping with ‘\n’, but it is stil a problem with vector: if i write:std::string s1 = “qwerqwr\n”; // for example int i = 0; *ssv[i] << s1;But give
-
skaffman
c++ char argument-passing stringstream const-char
I have a function for writing ppm files (a picture format) to disk. It takes the filename as a char* array. In my main function, I put together a filename using a stringstream and the << operator. Then, I want to pass the results of this to my ppm function. I’ve seen this discussed elsewhere, often with very convoluted looking methods (many in-between conversion steps). What I’ve done is shown in the code below, and the tricky part that others usually do in many steps with temp variables i
-
highBandWidth
c++ r osx-snow-leopard stringstream rcpp
It seems std::stringstream doesn’t work with Rcpp. To isolate the problem, I wrote a minimal program:#include <string> #include <sstream> #include <Rcpp.h>float atof(std::string a) {std::stringstream ss(a);Rf_PrintValue(Rcpp::wrap(a));float f;Rf_PrintValue(Rcpp::wrap(f));ss >> f;Rf_PrintValue(Rcpp::wrap(f));return (f); }RcppExport SEXP tsmall(SEXP sR) {std::string sC = Rcpp::as<std::string>(sR);return Rcpp::wrap(atof(sC)); }tsmall should just convert a string to flo
-
Pedro d’Aquino
c++ unicode stl stringstream
Given that the following snippet doesn’t compile:std::stringstream ss; ss << std::wstring(L”abc”);I didn’t think this one would, either:std::stringstream ss; ss << L”abc”;But it does (on VC++ at least). I’m guessing this is due to the following ostream::operator<< overload:ostream& operator<< (const void* val );Does this have the potential to silently break my code, if I inadvertently mix character types?
-
Jace
c++ stringstream uint64 char-pointer
I’m working on a game and I ran into a strange little issue… I was wondering if anyone here would be able to figure this out and explain it to me (it’s eating me up!)Firstly, here’s the relevant code.// even if this data is not set, it returns “” // so it’s pretty much never null // but if the function returns something, // it will be the string representation of a 64bit unsigned int const char* c_KickID = GetGameData(“kick_member_id”);//gets my ID, works fine. unsigned long long myID = GetM