C++ :: Update Container Value On Element Modify?
Sep 2, 2013
I'm trying to make dynamic status bar. How? I will create class, where will be function add(const string text, T value)
How it should be it in code which I want.
std::vector<string, T> cont;
void add(const string text, T value) {
cont.push_back(text, value);
} int ex = 1;
add("Example", ex);
ex = 12;
for(int i = 0; i < cont.count(); i++)
std::cout << cont[i]; // print "12"
View 7 Replies
ADVERTISEMENT
Sep 7, 2014
I tried to modify staff name with an assignment value of other string but couldn't work it out. I managed to modify it by key in cin >>.
The purpose is that I want to assign string value from other different class to Staff class. An error : no match for 'operator=' in '* updateName = newStaffName' and note: no known conversion for argument 1 from 'std::string {aka std::basic_string<char>}' to 'const Staff&' occurred.
#include <iostream>
using namespace std;
class Staff {
friend ostream& operator << (ostream& os, Staff& m) {
os << "[" << m.ID << ", " << m.fName << "]";
[Code]...
View 3 Replies
View Related
Mar 10, 2014
So I have linked list and function which deletes element if next element is bigger, so my code is working but its not working with first element, in the comment I have wrote code which I would code for checking that first element, but when ever I check it is blowing up all program.
#include <iostream>
using namespace std;
struct llist {
int x;
llist *next;
[Code] .....
View 1 Replies
View Related
Feb 23, 2013
I have a global list that contains smaller lists of char arrays. I have an issue where when I'm reading back the inner lists the last element of one list seems to point to first element of the next.
So my data looks like the below (values separated by commas with the pairs separated by tabs. The last pair in a line is the same as the first). When I read the first list back instead of seeing "456.678,678.98" as the last element in the list. I see "435.67,234.98" twice: at the end of the first list and start of the other. I have debugged when the list is populated and can see the correct values going in so I can't figure what's happening.
456.678,678.98 123.45,345.56 256.67,789.98 456.678,678.98
435.67,234.98 123.65,342.56 987.78,678.34 435.67,234.98
Code to fill the list:
obstacle_list = op_prg_list_create();
while (fgets(line, sizeof(line), obstaclePositions_traj_file) ) {
token = strtok(line, "
"); //Pull the string apart into tokens using the
input = op_prg_list_create();
[Code] ....
View 3 Replies
View Related
Aug 23, 2012
I have an std list of type double.. and the list is always guaranteed to have just 2 elements. I need to get the value of element 2 minus element 1. What is the least amount of code to accomplish that?
I tried this:
Code:
list<double> dList;
dList.push_back(1.0);
dList.push_back(2.0);
list<double>::iterator iter = dList.begin();
list<double>::iterator iter2 = dList.end();
double result = *iter2 - *iter;
But this code does not work. Why not?
View 6 Replies
View Related
Jul 24, 2013
All i want to do is modify a header of a file(.exe file). I just want to do if for fun and see what I can do with it.
View 3 Replies
View Related
Jun 17, 2014
I have a std::vector<int> and I want to modify subset of the elements. I thought I might be able to use:
std::vector<int> a = { 1,2,3,4,5,6,7,8,9 };
std::vector<int> b(&a[3],&a[7]);
for(auto& each : b) {
each++;
}
for(auto& each : a) {
std::cout << each << "
";
}
but that didn't work. The elements of 'a' retain their original values. Then, I thought, "Ooo, maybe I could make 'b' a reference." Nope. What approach would be to access a subset of a vector for potential alteration?
View 3 Replies
View Related
Jun 10, 2014
I'm trying to modify a library of a code and do not know exactly how to do it.I'm modifying the .cpp file and I know (as I have read on the internet) that I should compile it to obtain the .a file, because the main.cpp uses the .a file.I have written in the terminal the following command (founded on the internet):gcc -o analysis.hpp -c analysis.cpp but I still get an error.
View 3 Replies
View Related
Apr 7, 2013
After the data is in the array, prompt the user to modify the array by inputting a species name and a count. If the species is not in the array, print a message indicating this and add the species to the end of the array. If the species is in the array, change the count in the array to the new count. Allow the user to input any number of changes.
This is what I have so far:
//Description of program:Manages a list of bird species and counts stored in an array of structs.
#include <fstream>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <string.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <cstdlib>
using namespace std;
#define ARRAY_SIZE 200
[Code] ....
View 3 Replies
View Related
Apr 22, 2014
My problem is that I have to modify only some specific details in a txt file (actually it is a wrl file but it can be considered as a txt file). There is a lot of text there but I just need to modify the point coordinates and leave the rest of the text as it is. Reading the "sample file" at some stage we will see some blocks that look like the below:
coord Coordinate {
point [
# bottom
-1.0 -1.0 1.0, #vertex 0
1.0 -1.0 1.0, #vertex 1
[Code] ....
where the numbers are (X,Y,Z) coordinates. What I have to do is to change those figures for (X,0,sqrt(X^2+Z^2)) points. Therefore the expected result (test file) will be as follows:
coord Coordinate {
point [
# bottom
-1.0 0.0 1.4142, #vertex 0
1.0 0.0 1.4142, #vertex 1
[Code] .....
So in my opinion it can be good to have two files: sample.txt and test.txt where the sample file will never be modified whereas the test.txt will be the same as sample.txt but including the modifications as explained above. The idea can be to read the sample.txt, store the info and then start copying each line in the test file until we get to the points coordinates (which needs to be modified) and continuying with this process until the next set of coordinates.
The problem is that I do not know how to change x,y,z coordinates from the sample.txt to (X,0,sqrt(X^2+Z^2)) and to copy them in the test.txt. Please see some code below and the sample.txt file attached.
//Read a Text File///////////////////////////////////////////////////////////////////////////////////////////////////
using System;
using System.IO;
namespace readwriteapp {
class Class1
[code]....
View 4 Replies
View Related
May 27, 2013
I have made a Student record system in c++ using the concept of linked list. The program will take the student id, name and marks for 3 different exams. Then it will calculate the aggregate percentage based on those exams marks and display the relevant message according to the aggregate percentage. All is going well. But there is only one problem. When I modify the student record especially the marks, it doesn't change the aggregate percentage of that specific record. It shows the old one. Similarly the relevant message doesn't change too.
Code:
struct student{
int id;
char name[MAX];
string status;
double aggr;
int matric_marks, inter_marks, entryTest_marks;
[Code] .....
View 3 Replies
View Related
Aug 24, 2014
class MyOwner {
...
int m_count;
bool b_locked;
};
[Code] ....
I am using an API where I create many MyObjects on the heap, and the API uses a separate thread to send messages to each object. Each MyObject contains a pointer to MyOwner.
Suppose I want to keep a count of all messages received in all MyObjects: How can I do this in a thread safe way?
I am assuming that the code I have written above will not be safe--at the very least it seems that it would potentially miss message counts when it was locked--not the worse case scenario for me. I am most concerned about not causing the application to crash.
View 5 Replies
View Related
Feb 5, 2014
Using WPF and .NET 4.0 what would be the best way to utilize one panel but modify it for various options? For instance when having a basic or advanced view how would I go about changign the area to add buttons or other items most efficiently?
View 4 Replies
View Related
Feb 4, 2015
I have a N queens (actually 8 queens to be specific) program that accepts the numbers in order by row. I need to get it so it accepts the numbers in order by column. At first glance I thought it was just one space different, but it turned out not to be and how to get the one space difference in there. My current code (which I'm aware isn't doing the column accepting right) is:
Code:
#include <iostream>
using namespace std;
int main() {
int board[8];
cout << "Enter the columns containing queens, in order by column: ";
for(int i = 0; i < 8; ++i) {
cin >> board[i];
[Code]...
What the output should be:
Code:
Enter the rows containing queens, in order by column:
7
6
5
3
4
2
1
0
.......Q
......Q.
.....Q..
...Q....
....Q...
..Q.....
.Q......
Q.......
What it is:
Code:
Enter the columns containing queens, in order by column:
7
6
5
3
4
2
1
0
........Q
.......Q.
......Q..
....Q....
.....Q...
...Q.....
..Q......
.Q.......
View 5 Replies
View Related
Apr 27, 2013
I've initialized a character array in my main, and passed it onto one of my functions convertToPostfix(char infix[], char postfix[]). It isn't a constant read only array (constant char*) ive explicitly initialized it to char postfix[] = "";
Code:
if ((nextChar > 47) && (nextChar < 58)){ //if its a digit
postfix[++postfixIndex] = nextChar;
while (infix[i + 1] > 47 && infix[i + 1] < 58){
nextChar = infix[++i];
postfix[++postfixIndex]=nextChar;//segmentation fault when assigning from infix to postfix**
}
View 3 Replies
View Related
Oct 8, 2014
i have to write a function to modify the input string by substituting each alphabetical character. for example, 'Programming' to 'Rtqitcookpi' (mod_int = 2).
View 1 Replies
View Related
May 15, 2013
I derived a class from CRecentFileList in order to set the number of displayed chars for MRU.
The problem is that if I open the app with 256 set for this number (it is read from .ini file) the display is correct. But after I change it to 10 for e.g., File menu width remains unchanged altghough MRU are correctly displayed on 10 (or at least file name lenghts) chars.
how can I tell to the menu to shrink to actual width?
View 10 Replies
View Related
Feb 26, 2013
I have the next program: if I comment the assignation mNum=num; or mCh=ch the segmentation fault don't exist.
#include <vector>
class Base{
public:
[Code]....
View 2 Replies
View Related
Apr 14, 2014
I'm having a problem trying to modify my patient's data. It seems to work, but once the block of code ends it does not save to the linked list.
Problem located in case M.
linked list template header: [URL] ...
patient header: [URL] ...
patient implementation: [URL] ...
#include <iostream>
#include "listTemplate.h"
#include "PatientRecord.h"
using namespace std;
char menu() {
char input
[Code]...
View 1 Replies
View Related
May 4, 2014
I tried to implement a string class and i want to modify a specific char in my string . I did operator over load but this code crash in this line
name [2] = 'k' ;
Why ?!!!!!!!!!!!!!
this is my code
# include <iostream>
using namespace std;
#include <assert.h>
class String {
public :
char *content ;
int size ;
[Code] ....
View 11 Replies
View Related
Apr 30, 2015
I'm trying to make a program that reads data from a text document and allows me to modify it. I am stuck with the display() function. I can get the printf statement to display all my array values except the char AD value. When I include flight[i].AD it causes the program to crash. When I run the program to only display the AD variable I get a bunch of weird symbols. I'm not sure where the program is going wrong because it seems to be storing values properly except for the AD variable.
#include <fstream>
using namespace std;
//named constants
const int MAX=100; //maximum flights
const int SIZE=20; //maximum characters
//struct definition
struct FlightType
{
char name[SIZE];
[Code]...
View 1 Replies
View Related
Feb 11, 2013
I wish to add the item 'Website' to an MFC Dialog app System Menu so that it can activate the following method:
Code:
void CMyDlg::OnWebpage()
{
ShellExecute( NULL, NULL, _T("[URL]..."), NULL, NULL, 0 );
}// OnWebpage()
I have tried this:
Code:
#define IDM_WEBSITE (WM_USER + 101)
//..
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
pSysMenu->AppendMenuW(MF_STRING, IDM_WEBSITE, _T("Website"));
}
[Code]...
The code compiles without error but and the 'website' item appears on the System Menu but it doesnt do anything.
I've inspected the following but don't really understand how it works and it seems to me there should be a simpler way to accomplish my end.
Modifying the System Menu By John Simmons 26 Jan 2007 [URL]....
View 8 Replies
View Related
Sep 23, 2013
i want to modify value of whole array by passing it to a function and make each value of array multiplied by 3 ,return the value to main and print it using pointer.
error : invalid Lvalue is the error
Code:
#include<stdio.h>
main()
{
int i,arr[10];
for (i=0;i<=9;i++)
{
printf("Enter value of arr[%d] : ",i);
scanf("%d",&arr[i]);
[Code] ....
View 1 Replies
View Related
Aug 21, 2014
In case the question was not very clear. Say I have the following code:
int sum(int * x, size_t N){
int sx;
/* returns sum of elements in x */
return sx;
[Code] ....
I'm curious to know whether there is a way that ensures a function does not modify the memory pointed to by a pointer.
View 9 Replies
View Related
Feb 10, 2015
I am unsure how to write a function which modifies the content of the 1D character array and puts all of the letter it contains into uppercase. the following are the letters which i am trying to convert.
char text[MAX+1] = {'T', 'e', 's', 't', 'e', 'r', EOT};
The output to this should look like T E S T E R EOT
View 2 Replies
View Related
Aug 19, 2013
I want to search and display the field stored in text file and also i want to delete the field that is entered. Case 3 and 4 is incomplete.
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main() {
int a;
int st_id;
[Code] ....
View 6 Replies
View Related