I have a string and i want to conver the part of it to an int. I want to convert the part of the string `input[1]` to an int. But my compiler cant use atoi, or stoi.. I saw a ifstringstream option i think can work, but i tried implementing it but it didnt work.. Here is what i have. int currentqueue = 0; std::stringstream converted(input[1]); currentqueue = converted; What is wrong here?

Member Avatar
Member Avatar
+0 forum 5

the basic idea is that i have a config file where i need to take entries in different formats(the key is always a string and the value could be any type: int, float, string etc) from and the file has the following style: firstentry 1.5 secondentry 35 thirdentry somestring and i have this code to try to read int values from the entries but it gives me a lot of errors: #include <iostream> #include <fstream> #include <sstream> #include <string> #include <map> #include <Windows.h> using namespace std; map<string, stringstream> entries; int ReadInt(const string& key) { int value; stringstream SS; for(auto i …

Member Avatar
Member Avatar
+0 forum 2

I'm trying to make a program for my computer science class and it requires that I run output to the console as well as to a file. I'm looking for a way to intialize a string at the beginning of the program and pass the variable by reference to my functions. The functions will then append strings to the intialized variable. I need to be able to also set precision and justification for floating point variables that will be appended to the string. I am working with stringstream right now but every time I return the output string that I …

Member Avatar
Member Avatar
+0 forum 2

Hello, people on daniweb. I was programming in C++CX for a metro application I am making, and needed to do a little string manipulation. Does anyone know if there is a way to individually edit members of String^, like an array, or if there is some equivalent to stringstream on C++CX? Just wondering, as the documentation isn't as complete as some as it is in beta. Thanks, ahead!

Member Avatar
Member Avatar
+0 forum 7

hi, i have this code: [CODE]#include<iostream> #include<sstream> #include<string> using namespace std; int main (char argc) { string n1 = "141+246+3+64"; int n2; int pos = -1; char toFind = '+'; do { pos = n1.find(toFind, pos+1); if(pos != -1) { stringstream(n1) >> n2; cout << n2 << endl; cout << n1 << endl; cout << pos << endl << endl; n1 = n1.substr(pos); } } while( pos != -1 ); system("pause"); } [/CODE] this is the output: 141 141+246+3+64 3 246 246+3+64 5 Press any key to continue . . . I dont know why it wont find all of …

Member Avatar
Member Avatar
+0 forum 2

hi, I am trying to make a calculator and I need the stringstream function to convert a a certain part of a string.[CODE]string n1 = "243+79"; int n2 = 0; stringstream(n1[0-2]) >> n2; // this converts the 243 from n1 to an int[/CODE] Any solutions?

Member Avatar
Member Avatar
+0 forum 7

hi, i am trying to make a calculator and i have this code [CODE]#include<iostream> #include<sstream> using namespace std; int main (char argc) { int l = 1; for(l = l; l > 0; l--) { int q = -2; string n1 = "1+5"; int n; int e; stringstream(n1[q=q+2]) >> n; stringstream(n1[q=q+2]) >> e; cout << n + e << endl; } system("pause"); } [/CODE] this is just a test program i use to figure out hard problems with the original one. so if i dont use stringstream, the answer doesnt come out right. any solutions?

Member Avatar
Member Avatar
+0 forum 3

Hi, i'm getting only one digit after floating point after conversion from string to float. Have tryed from standart functions to i don't know.. the problems is that conversion whatever it would be (strtod(), stringstream >> float, atof(), don't even rembember all other wacky ways to do that) brings me only one or none (if i have number.00) digits after floating point. Would be very happy to hear something that might help.. p.s. oh, if that matters - i get string from file via getline..

Member Avatar
Member Avatar
+0 forum 4

I'm trying to write a to string function that would use std::stringstream to convert the the instance data into a string, but haven't been able to get operator overloading to work with it. As soon as I define a new << operator, I get a bunch of ambiguity errors saying that there are multiple overload for the operator that could fit. I'm using a trial version Visual Studio 2010 Proffesional, and had the same problem using Visual C++ 2010 Express. Here's the code, and the line that's causing the error is "stream << someobject.num;" [code] #include <sstream> #include <iostream> class …

Member Avatar
Member Avatar
+0 forum 6

I'm developing a game engine, and set up a function that uses string streams to convert various values into std::string's. To use this to string function on class obviously takes an overloaded insertion operator, which I have done for a transformation matrix class here: [code] typedef std::stringstream StreamString; StringStream& operator<<(StringStream& stream, const TransMatrix& matrix) { for (int y = 0; y < 4; y++) { stream << "{ "; for (int x = 0; x < 4; x++) { stream << matrix(x, y) << ((x < 3) ? ", " : " }\n"); }; }; return stream; }; [/code] I'm …

Member Avatar
Member Avatar
+0 forum 3

Hello everybody, is there somebody that can help?? I'm having string (my example in string 55+22)that must be inputed by keyboard .. the first part I've done to put 55 to another array 2(with strtok function) Now that I was tries for many hours to put 22 to an other one was failed :@:yawn::sad::-/ if there is anyone that can put char firststring[] = [55+22]//put to another string or copy In such way that each time program work it finds + and copies 22 it is easy

Member Avatar
Member Avatar
+0 forum 8

hello, [B]I have an assignment for my one class at school where I am supposed to write a program that creates lists of people who have met. Each line of input is a space-separated list of the names of people who have met. If a person is in a group with someone, they have met and should be on each other's contact list. The input is multiple lines of groups of people terminated by end-of-file[/B] for example: beth david mark helen helen ben faheem eric mavia sarah mindy ...etc [B]I am allowed to use any C++ data structures, and I …

Member Avatar
Member Avatar
+0 forum 3

Hello, I need to simulate a stream which behaves exactly like a ostringstream, except when handling objects of type color. What is the best way to do this? [code] user.display() << color() << "Name: " << color(color::Red) << setw(10) << left << str_name << endl << color() << "Date: " << color(color::Green) << setw(10) << right << int_date << endl; [/code] should display the same as... [code] user.display() << color() << "Name: " << setw(10) << left << color(color::Red) << str_name << endl << color() << "Date: " << setw(10) << right << color(color::Green) << int_date << endl; [/code] I …

Member Avatar
Member Avatar
+0 forum 1

The End.