C++ :: Existing Code For String To Expression?
Apr 17, 2012
I would like to get hold of the code for a function that takes a string as input argument and returns a numerical value, either integer or double, according to the the expression represented by the string. For example the string may look like this:
Code:
"(256 * d3 + d4) * factor - offset"
then the function would calculate the value of
Code:
(256 * d[3] + d[4]) * factor - offset
where d is an integer array, factor and offset are double or int variables or constants. For my application the name for the array can be fixed to be "d", and the names for other variables and constants are known. The closest thing I could find on-line is this:
[URL]
which only does literal integer calculations, no double, no variables or constants. Are there existing code that does what I need or do I have to write my own?
View 2 Replies
ADVERTISEMENT
Aug 13, 2014
I've got some code in C++ that does some basic analysis on price data and I run it from the cmd prompt. One of the functions I had built to read in the data is as follows:
void ReadPricesFromFile(constchar*filename,std::vector<PriceInfo>&prices)
{std::ifstreaminput(filename);
input>>prices;}
How would one merge this type of code into a Qt GUI? Ideally, I'd like to use something like QFileDialog to open up a folder with my data files, select a file, and then read the file that the user selects. Would the main.cpp look something like this?
int main (int argc, char *argv []) {
QApplication prog (argc, argv);
QPushButton *load_button = new QPushbutton ("Load File");
QObject:: connect (load_button, SIGNAL (clicked()), &prog, SLOT ( (ReadPricesfromFile function?);
load_button-> show ();
return prog.exec ();}
View 3 Replies
View Related
Feb 14, 2014
I wrote a program that tries to tokenize a mathematical expression, inserting the tokens in a list of strings. The list is as follows:
typedef struct listOfStrings {
char **array;
int size;
} ListOfStrings;
There is even a function to initialize the listOfStrings. The thing is: I'm printing a token every time it is complete and every time it is inserted in the list. The output is okay. However, when all tokens are processed and I call function print_list_of_strings to print the tokens again, the first token is printed with a leading garbage value if the input for the program is "3 + 4 * 2 / ( 1 - 5 ) ^ 2 ^ 3". How is this possible? The code for printing the list is as follows:
void print_list_of_strings( const ListOfStrings *const lPtr ) {
int i;
int numberOfElements = lPtr->size;
if ( numberOfElements != 0 ) {
for ( i = 0 ; i < numberOfElements ; ++i ) {
[Code] ....
The list just prints --- if it's empty, although this isn't the case for the program I'm writing. Also, if the input is "1 + 2", everything goes fine. The code for inserting at the list is:
int insert_at_end_of_list_of_strings( ListOfStrings *lPtr, const char *const str ){
int lengthOfStr = strlen( str );
int numberOfElements = lPtr->size;
if ( ( ( *( lPtr->array + numberOfElements ) ) = ( char * )malloc( ( lengthOfStr + 1 ) *
[Code] ....
View 5 Replies
View Related
Apr 9, 2012
<IMG border=0 alt="UserDeviceId = 70813215">
Above is the sample string object from this i need to find the integer value of UserDeviceId.
View 2 Replies
View Related
Apr 17, 2013
I wanna to know how can i get a string from the user and treat it as a c++ code ..is there any way to do that ??
View 7 Replies
View Related
Aug 5, 2014
#include <iostream>
#include<fstream>
using namespace std;
int main() {
string choice, meaning, word, yesOrno;
char add[20];
[code]....
i have done my best but i have still problem with searching words from previously saved words from user this code it keeps adding but it won't display when i search for.
View 10 Replies
View Related
Jul 6, 2014
I'm trying to edit an existing xml file but with no luck. I'm new to xml environment.
This is the xml content :
<?xml version="1.0" encoding="UTF-8"?>
-<mmp>
<ID>aaa</ID>
<clientID>bbb</clientID>
<time>2004-05-10T17:35:41.29</time>
<session>2000</session>
<Answer>Yes</Answer>
-<Program>
<_id>ppp</id>
</mmp>
I'm trying to change the time and id values and can't do it.I tried almost anything.
View 4 Replies
View Related
May 23, 2013
I'm trying to write a program that prompts the user to enter a math expression (i.e 2*x + x*x) and a value of x. Then generate the value of y. My real question is: Is there a way to put the content of a string into the source code?
Example:
string math_function;
double x, y;
cout << "Enter the function: ";
getline(cin, math_function);
[Code] .....
View 4 Replies
View Related
Feb 10, 2013
I created a .txt file that I called in.txt. It has the letters: a b c d e. I put it in the same folder as the c++ code below. I was hoping that I after I compile and run the code, the in.txt file would read: e d c b a. Unfortunately, it doesn't. Even when I give the ofstream file another name, it does not create another text file.
Code:
#include<iostream>
#include<fstream>
#include <limits>
[Code].....
View 7 Replies
View Related
Feb 27, 2012
I have the following code that prints out only the first char of each string. Why does it not print out the entire unsgined char* ?
Code:
#include <iostream>
#include <vector>
using namespace std;
void PrintVector(vector<unsigned char*>& data) {
for(size_t i = 0; i < data.size(); i++)
[Code] .....
View 5 Replies
View Related
Dec 28, 2014
Let's say I have an exe-file (for example computer game) and need to forbid to run it until certain date or time during the day. Any 'manipulations' with file are allowed. offer me a simple way of how to encode/decode such a file?
View 7 Replies
View Related
Mar 26, 2013
I have an array of char representing pixels in a bitmap, which I want to modify. I don't think I can just iterate over the array and pass chars into a function individually, because the function needs to take into account the neighboring pixels, too.
I thought of two ways to do this. The first would be to pass the array to the function as an argument, then have the function change it and return it. The trouble is I'm not exactly sure what happens internally when you pass an array to a function and return it. Is it the same array, modified? Or is it a copy of the array, so now you're using twice as much memory?
Alternatively I guess I could have a function with a void return type and pass a pointer to the array. I'm somewhat new to this, but the way I understand it is that a pointer is like the address of a house, while the array is the actual house. So if I give the function the address, it can go to that address and rearrange the furniture inside the house. Then, after the function returns, I can go to that address myself and see all the rearranged furniture, even though the function has already returned.
Is there a problem with the second way? It seems a bit neater, but maybe I'm understanding pointers wrong.
View 14 Replies
View Related
Nov 5, 2014
This program gets input from a file and output to the screen and to a file. The difficulty I am having is summing the number I retrieve from the file for the individual numbers of sightings.
#include <fstream> // enables us to read and write files
#include <iostream> // for cin and cout
#include <cstdlib>
#include <string> // enables us to hold strings of characters
#include <cctype>
using namespace std;
[code].....
View 14 Replies
View Related
Oct 5, 2013
adding a column in ms access database and update it with a value.Here is my code, it gives an error that says syntax error in field definition.
string myConn = " ";
myConn = "Provider=Microsoft.ACE.OLEDB.12.0;
Data Source=C:/Users/EmployeeAttendanceRegister/EmployeeAttendanceRegister.accdb";
OleDbConnection myCon = new OleDbConnection(myConn);
string myInsert = "ALTER TABLE Attendance ADD COLUMN SignIn" + dateTimePicker1.Value;
[Code] .....
View 1 Replies
View Related
Apr 13, 2015
Is there some quick way of resetting the contents of an existing array to 0? Just to be clear, I'm not initializing the array, it already exists, has content and needs to be reset at 0. Is there a faster way than the code below?
Code:
for(i=0;i<100;i++)myarray[i]=0;
View 6 Replies
View Related
Nov 10, 2013
C++ Code To Print String through Installed Printer. How to user Printer File Name?
View 9 Replies
View Related
Jul 16, 2014
I've tried a bunch of alternative methods to prevent an assertion error. "not understanding" the bug and why I'm getting it are relevant here, not proper, (or more appropriate), coding methods. I would write it in another way to prevent the error, I simply want to understand what is happening during run-time that causes the situation.What is the bug?
---------------------------------------
[assertion error]
[expression _block_type_is_valid(phead->nBlockUse)]
--------------------------------
Code:
#include <iostream>
#include <string>
using namespace std;
int main() {
cout << "Enter your name : ";
string Name;
[code]...
View 1 Replies
View Related
Oct 6, 2014
My user requires that I add function to an already working C server that will send to another host via http post and existing xml file. I have googled and found C# and C++ on how to do this but nothing using C. Where do I start?
View 1 Replies
View Related
Feb 15, 2015
is it better to reuse an existing variable or create a new variable for the following situation:
/* Is this faster: */
glm::mat4 newViewModelMatrix = (*existingViewMatrix) * (*existingModelMatrix);
/* Or is this faster? */
glm::mat4 existingViewModelMatrix; /* declared in class header - initial value assigned in class constructor */
existingViewModelMatrix = (*existingViewMatrix) * (*existingModelMatrix);
Just wondering if it makes a difference or not.
View 1 Replies
View Related
Jan 14, 2013
I am trying to add in a few 3rd party libraries to an existing project solution. I have no source code or knowledge on how the libraries were built (i.e. what run-time library was used). I have recieved the following errors and warnings:
1>CAPS_LIB.lib(PCEfunc.obj) : MSIL .netmodule or module compiled with /GL found; restarting link with /LTCG; add /LTCG to the link command line to improve linker performance
1>libcmt.lib(getenv.obj) : error LNK2005: _getenv_s already defined in MSVCRT.lib(MSVCR90.dll) ***There are multiple of these errors
1>LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>MSVCRT.lib(cinitexe.obj) : warning LNK4098: defaultlib 'libcmt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
1>libcmt.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
1>C:Program Files (x86)BCI 2000 v3progRelWithDebInfo..CAPSVRInterface.exe : fatal error LNK1120: 1 unresolved externals
CAPS_LIB.lib is one of the libraries I am trying to add in and it seems to be the one causing the problem. I believe I have added in all three libraries into the project solution correctly, but I can't seem to find a solution to these errors.
View 2 Replies
View Related
Feb 20, 2014
I have made a program that converts or reverses an input string. Here is my code working fine
static void Main(string[] args){
string input = Console.ReadLine();
string[] words = input.Split(' ')
for (int i = words.Length; i > 0; i--)
Console.Write(words[i - 1] + " ");
Console.WriteLine();
Console.ReadLine();
}
How can I write this program in pseudo code?
View 2 Replies
View Related
May 12, 2013
I am just learning using class template but I keep getting error unable to match function definition to an existing declaration
template <typename T>
class Homework {
private:
string name;
public:
template <typename T>
void SetName(T val);
[Code] ....
View 10 Replies
View Related
Apr 13, 2013
I've written the following code and keep getting the errors:
Error1error C2244: 'Supermarket<temp>::operator =' : unable to match function definition to an existing declaration
Error2error C2244: 'Supermarket<temp>::setName' : unable to match function definition to an existing declaration
Error3error C2244: 'Supermarket<temp>::setArea' : unable to match function definition to an existing declaration
#ifndef SUPERMARKET_H
#define SUPERMARKET_H
#include<string>
#include<iostream>
using namespace std;
[Code] .....
I moved the files to the .h file, and now I'm getting
Error2error LNK1120: 1 unresolved externals
View 11 Replies
View Related
Sep 10, 2014
I basically want to develop an application which print an existing file on reception of a network event (application will be running on a seven 64 bits PC).
I wonder which application type would be the most suitable (and the simplest) for that (console win32, win32 app, MFC app ...). As this application does not need user intervention (print on network event), I'm not sure that I need a MFC application or a win32 app.
View 9 Replies
View Related
Apr 15, 2013
I have assignment which requires me to print out and array code and a pseudo code. I dont no what a pseudo code is,.
View 2 Replies
View Related
Jan 1, 2013
My question is while I'm reading this book step by step line by line, I reached this example. Building classes then derived classes. How can I add derived class from a class which is already existed. In other words, I have Person Class (which is my base class) and after implementing this class, I would like to create Student Class ( which is my derived class). How can I do that from using Solution Explorer window? I can add base class and derived class together by right click on my project and then add new item then adding class + base class I know that but what if my class in this case existed and I want only to add base class? I know how to add cpp. file and h. file but I want to take advantage of using the formal style if it exists in this case.
View 4 Replies
View Related