C++ ::  How To Extract And Modify Sub-Vector

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


ADVERTISEMENT

C++ :: Extract Text To Vector?

Apr 5, 2013

im trying to extract this

1 2 3 4
5 7 8
9 6 10 11
13 14 15 12

into a vector where the blank space can variate and the numbers can switch.How can i get this working?

View 1 Replies View Related

C++ :: How To Modify A Header Of Any File

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

C++ :: Modify Library Of A Code

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

C++ :: How To Let The User To Modify The Counts

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

C# :: Modify / Create Txt File?

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

C++ :: How To Modify Data In A Linked List

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

C++ :: Multithreading - How To Modify Shared Object

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

C# :: Utilize One Panel But Modify It For Various Options?

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

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 View Related

C++ :: How To Modify A Program So That It Accepts Columns Instead Of Rows

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

C :: Segmentation Faults When Trying To Modify A Character Array

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

C++ :: Write A Function To Modify The Input String?

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

Visual C++ :: How To Modify File Menu Width

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

C :: How To Extract Data From Txt File

Jan 13, 2015

I managed to read txt files and printing them on the console window. I was given a task to select and sample a certain amount of data.

Example of txt file:

Voltage (V),Current (I),Power (W)
50,2,100,
51,2,102,
52,2,104,

etc.. How can I display only the column of Voltage and Power?

View 1 Replies View Related

C++ :: How To Extract Output From IF Statement

Feb 9, 2015

I need to use the output of my IF statement in a calculation. But how can i extract the output from the IF statement in my code?

#include <iostream>
#include <cmath>
using namespace std;
int main(int argc, char *argv[]) {
double x, y, z;
cout<<"Please enter the student's three test grades:"<<endl;
cin>>x>>y>>z;

[Code]...

I need to use the output in my average.

View 3 Replies View Related

C++ :: Extract Comments From C File

May 21, 2014

I need to extract comments from a C file, which are usually marked with " /* This is a comment */ ". It seems to me that I need to calculate first at what position is the / and then ask it if on the very next position to the / operand is the *, if it is then I need check where is the next * and if / operand is immediately next to it. At last I need to take everything between values that the first and second * have. But I don't know how to write that in code.

This was supposed to be done in c++.

View 5 Replies View Related

C++ :: Extract File Name And Extension From TXT?

Aug 10, 2012

I have a list of files stored in a .txt file

$codeguruc++display.txt$15$

Directory File Folder: codeguruc++
File Name: display.txt
File Size: 15kbs

$ is an delimiter

I want to extract the name and the extension from txt files.

Code:
#include <iostream>
#include <fstream>
#include <cstdlib>
struct MyFile {
std::string Directory;
std::string Filename;
unsigned filesize;

[code].....

View 6 Replies View Related

C++ :: Extract Some Images From ADF Files

Jul 31, 2013

Its to extract some images from .adf files, I have had it working about 2 years ago but now i cant figure out the right directory.

Code:

using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
namespace ADFReader{
class Program {
public static int ApplyOffset(int data, int offset)
[Code] ...

The main problem is

Code:
static void Main(string[] args) {
foreach (string file in Directory.GetFiles(@"data", "*.adf")) ;
{
byte[] bytes = File.ReadAllBytes(file);

[Code] .....

View 1 Replies View Related

C++ :: Modify A Member By Static Cast Cause Segmentation Fault

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

C++ :: Unable To Modify Object Data In Linked List

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

C++ ::  Modify Element In Node Of Linked List With Value Assignment

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

C/C++ :: Implement String Class And Modify Specific Char

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

C/C++ :: Program That Reads Data From A Text Document And Allows To Modify

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

Visual C++ :: How To Modify System Menu To Execute A Function

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

C :: Parsing A Line To Extract A Particular Substring?

Mar 14, 2014

Suppose I have read a line from an ASCII file with fgets(). Now I want to parse the line, which looks something like this: Code: # John Q. Public et al. 2014, to be submitted The name, "John Q. Public" is what I want. However, the name can be anything, consisting of 1 or more tokens separated by spaces. it could be "John" Or "John Public", or "Thurston Howell the 3rd", or etc... Bascially, I need to get the entire substring between the first hash mark, and the "et al" in the line. I tried this: Code: sscanf(line,"# %s et al.",name); But I can only get the first token (which, in this case, is "John").

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved