C++ :: Getting Multiple Ints From String Data

Feb 18, 2013

I'm having trouble making a .obj loader at present I'm trying to load faces that are defined as follows:

f 1/1/1 2/2/2/ 3/3/3

So far I've separated the the three number groupings into three strings, I've had a few issues with stringstreams and would like a simple solution.

View 1 Replies


ADVERTISEMENT

C/C++ :: Converting String Of Ints To A Vector Of Ints?

May 8, 2014

I am getting a string from the consle and that all works fine. I'm expecting a string of number, ie 123456.... I store that fine in my string object. I then need to take each individual number, ie 1, and put it in a vector then take the next number, ie 2, and put that in the next element in my vector.

Everything i've found and does eaither takes the entire string and stores it as an int, or takes the ascii representation of the number and stores that. How do I seperate each individual number and store them seperatly. below is a few different variations i've tried that doesn't produce my desired results.

cout<<"Please type the memory memory frames (numbers 0-9) to be used to simulate the input memory "<<endl;
cout<<"Your input: ";
string line="";
cin>>line;
cout<<"
Please wait while your input is processed and validated..."<<endl;

[code].....

the only thing i havn't tried yet is string streams and i don't necessarly like using them. Am i going to have to go that route? will that even work?

EDIT:I forgot to mention that this is being done on linux and then ported to unix.

View 7 Replies View Related

C++ :: Combine Multiple Vector Containing Binary Data To String?

Mar 16, 2012

Two questions:

1. I have some vector<unsigned char> containing binary data. I would like to combine them into one std::string. How is the correct way to accomplish this?

This is my best guess for sample code:

Code:
vector<unsigned char> data; //conatins some data
vector<unsigned char> data2; //contains more data
string temp(data.begin(), data.end());
temp.append(data2.begin(), data2.end());

Will this code work with binary data, or will it null terminate?

2. A similar problem.. I have some unsigned char* variables, and I want to combine them into one std::string. How can I accomplish this? will the member append() work here? or will it null terminate? Something like:

Code:
unsigned char* data; //conatins some data
unsigned char* data2; //contains more data
string temp(reinterpret_cast<const char*>(data));
temp.append(string(reinterpret_cast<const char*>(data2)));

Will the above sample code work without null termination?

View 4 Replies View Related

C# :: Creating Complex Number Calculator - Convert String To Ints

Sep 18, 2012

I am working on an assignment to create a Complex number calculator. In this assignment I am to ask the user for input to the calculator. We are given a sample run output that looks like this.

Enter operand1: 3 4
operand1: (3, 4)
Enter operation : +
Enter operand2: 1 2
(3, 4) + (1, 2) = (4, 6)

My question is how would I take from the user: an integer followed by a space followed by another integer and convert that into two seperate accessible int values that I can save as real and imaginary values.

View 4 Replies View Related

C++ :: Map Storing Multiple Data Types

Jul 11, 2014

I am trying to create a generic map container which shell contain data of different datatypes. I already found a solution in this forum here:

[URL]...

Introducing a container with a Base Class as content type and inserting objectes of Derived Class types from that Base Class suites my implementation very well. But it is not really working. I implemented it this way:

class MyType {
public:
MyType() {}
virtual ~MyType() {}
}; template <class PT> class ParseType : public MyType

[Code]...

Then I insert one element.

// index being an object of type Parser<string>
ParseType<string>* test = new ParseType<string>( index );
// and index.val(0) = "-n"
iMap.insert( pair< string, MyType* >( index.id(0), test ) );

Now I think I should be able to call

const string key("-n");
iMap.at(key)->content->val(n);
Or
iMap.at(key)->get_val(n);

But neither one compiles with the error that "class MyType" (as the map container is pointing to a MyClass object) has no member/member function "content"/"get_val".

I also tried introducing member and member function "content" and "get_val" in "class MyType", which I thought should be hidden while constructing ParseType<string>. This would compile but it does not call the member "content or member function "get_val" from class ParseType.

A second try was to remove templatization of "class ParseType" and introduce a specific, let's say, "class ParseString" for objects of type Parser<string>. But the problems remain the same either the compiler complains due to missing member/member function or retreiving the map content will not call the derived class member/member function.

View 4 Replies View Related

C++ :: Accept Multiple Data Types

Jun 17, 2014

Basically I do not want to use a menu, instead just accept either an float or a single character. Then send the data to the appropriate spot based on the user input. I have been unable to convert the char to a float, and even if I did the char would probably only accept the first digit, say user enters '15' it would only read the '1'. I've tried strings instead of char but then unable to use the isalpha function. Do I need a char[] and then iterate through to get the numeric data? Then how do i make '1' and '5' become 15. There is probably a solution. I've also tried to use a loop waiting for the correct data while(!(cin >> letter)) which works but how do I get out if the user enters number.

#include <iostream>
#include <cctype>
#include <string>
#include <cstdlib>
using namespace std;

[code].....

View 3 Replies View Related

C++ :: How To Write Data Into Multiple / Different Files

May 7, 2013

I am new to c++ programming i just want to know how to write the data into different files.Suppose my input files has 1-8 ids so each id data must be stored into each different file. And below is my code.

#include<fstream>
#include<iostream>
#include <cstdlib>
#include <algorithm>
#include<list>
#include <math.h>
#include<conio.h>
#include<string>
#define PI 3.14159265
using namespace std;
double angle;
ifstream indata;
ofstream outfile;

[Code] .....

View 1 Replies View Related

C :: Inputting Data From Multiple Lines Using Scanf?

Aug 1, 2013

How would I go about inputting data from multiple lines using scanf?

So far I have tried a loop and somehow checking for '' but can't seem to figure it out..

E.g I want to be able to scanf the ints below line by line and print them( if that makes sense) .

5 15 20 30 5 6
5 6 8 20 34
5 6 7
5 2
2 6 7 2 1 6

This is what i've tried so far, but am really lost!

Code:

int input;
while(scanf("%d", &input)){
printf("%d",input);
if(input == '
'){
continue;}}

View 13 Replies View Related

C++ :: Read Byte Of Char Data And Convert It Into Text String Of Binary Data That Represents Hex Value

Dec 26, 2013

I am writing a program where I need to read a byte of char data and convert it into a text string of binary data that represents the hex value...

i.e. The char byte is 0x42 so I need a string that has 01000010 in it. I've written the following subroutine....

------------- My Subroutine ----------------------------------------------------------------------
void charbytetostring(char input, char *output){
int i, remainder;
char BASE=0x2;
int DIGITS=8;
char digitsArray[3] = "01";

[Code] ....

When I submitted the byte 0x42 to the subroutine, the subroutine returned to the output variable 01000010... Life is good.

The next byte that came in was 0x91. When I submit this to the subroutine I get garbage out.

I am using a debugger and stepped through the subroutine a line at a time. When I feed it 0x42 I get what I expect for all variables at all points in the execution.

When I submit 0x91 When the line remainder = input % BASE; gets executed the remainder variable gets set to 0xFFFF (I expected 1). Also, when the next line gets executed..

input = input / BASE; I get C9 where I expected to get 48.

My question is, are there data limits on what can be used with the mod (%) operator? Or am I doing something more fundamentally incorrect?

View 6 Replies View Related

C++ :: Make A Table Class That Will Be Able To Have Multiple Columns Of Data?

Sep 17, 2014

I am trying to make a table class that will be able to have multiple columns of data. I want it to have something to hold data (I was using a 2D vector for only one data type) in it, somewhat like a pair, but for any number of data types. The class is a template to make it generalized.

I have looked a little at variadic templates, but I don't know how to declare the vectors for each data types then.

View 4 Replies View Related

C++ :: Multiple Data Streams In One Class - Handling All In One Member

Jan 24, 2014

I have to implemente the to_string method. Whats the fastest way? Stringstreams. But I have to use C++ without any headers, so I need to implement the stringstream class. How can an stringstream hold one float? An double? Hoq cqn I implement an strigstream myself?

View 8 Replies View Related

C++ :: Smart Accessor Function For Multiple Data Containers?

Mar 14, 2012

Suppose I'm writing a program designed to simulate a large company. I'm interested in tracking each company employee by the location where they work. This company has perhaps a thousand different locations:

class Employee {
public:
AccessorFunction1(); // does something
AccessorFunction2(); // does something different
AccessorFunction3(); // does something completely different
protected:
// Some data

[code]....

Once employees are created and pointers to them are saved in the proper Location vector, I write an accessor function, OrganizeLocation(), designed to do a number of operations on a given vector. The problem is, I have maybe a thousand vectors. How do I call this function and specify which vector I want?

Currently, I'm using this clunky solution:

void Company::OrganizeLocation(int a){
switch(a) {
case 1: {
for(unsigned int i=0; i<LocationA.size(); i++) {
LocationA[i]->AccessorFunction1();
LocationA[i]->AccessorFunction2();
LocationA[i]->AccessorFunction3();

[code]....

The key point here is that whichever vector I choose to operate upon, I'll do the exact same procedure every time. I hate this solution because it results in very long and repetitive code not to mention its very error-prone when you re-editing all those "LocationA 's into "LocationB/C/D/etc."

void Company::OrganizeLocation( string $WhichOne$ ){
for(unsigned int i=0; i<LocationA.size(); i++) {
Location$WhichOne$[i]->AccessorFunction1();
Location$WhichOne$[i]->AccessorFunction2();
Location$WhichOne$[i]->AccessorFunction3();
}

Or, if it can't be done in C++, is there a better design approach? Ultimately I need the Company object to hold multiple vectors but use one compact accessor function to perform operations on just one of them.

View 5 Replies View Related

C :: How To Use Multiple Delimiters On A String

Mar 19, 2013

This is part of a bigger program im working on that deals with data structures, but I'm trying to figure out a way to tokenize a long file of purchases that is being read to my program. I rewrote the program to pinpoint my problem. I need to get the name, cost, item and quantity from this string. I figured out how to look for the cost, but what about the name and item(shirts)? How can I do this all in one loop because there are multiple strings and i'm gonna eventually send all the info to a data structure for each person(name)? I'm only asking about the tokenizing part, but this code works for the cost.

Code:

int main(void) {
char myString[] = "Angela bought 9 shirts for $6 each." ;
char * del = " " ;
char * token ;

[Code].....

View 12 Replies View Related

C++ :: How To Take Multiple Line String

Feb 3, 2013

I want to take multiple line string in c++. How can I take this.

Such as I want to take this as input:

HELLO MY LOVE, I M HAPPY BECAUSE SOON I WILL BE TO YOUR SIDE.
THIS TIME WITHOUT YOU HAS BEEN ETERNAL.
I INVITE YOU TO THE ZOO ONE TO SEE THE ZEBRAS AND GORILAS.

View 2 Replies View Related

C/C++ :: Print Even Then Odd Ints From Stack

Feb 19, 2014

Given a stack with an equal amount of even and odd numbers: 4, 22, 15, 3. The output should be in any order: [even], [odd], [even], [odd].

int main() {
Stack<int, 4> stk; stk.ClearStack(); int x;
for (int i = 0; i < 4; i++) {
cin >> x;
stk.PushStack(x);

[Code] ....

Output is:

Wed Feb 19 20:09:10 2014
4 7 5 22 //input
22 5 4 //output

Press any key to continue . . .

I know the logic fails if the first number is not even, but I cant seem to figure out another way to do it.

View 14 Replies View Related

C++ :: Struct Of Ints Via Socket?

Feb 7, 2014

I have some paper work to do about a game I should be able to play with my class mates. We should be able to send and recive a struct concerning about the 'moves' of the pieces at the game. This struct is made of 4 ints, simple as that.

I had a previous paper work to do where I'd have to send ints and that was ok, but now that I have to send a struct I'm failing to do so. This is What I've tried:

//SERVER
struct message{
int code;
int piece;
int x;
int y;
}send;
bytes_sent=write(new_socket,&send,sizeof(message));
cout<<bytes_sent;

So far so good, I see 16 as bytes_sent's value.

On the other hand:

//CLIENT
struct message{
int code;
int piece;
int x;
int y;
}recive;
bytes_recvd=read(my_socket,&recive,sizeof(message));
cout<<bytes_recvd;

I always see 0 as the bytes_recvd's value.

View 3 Replies View Related

C++ :: Writing Data On A File In Binary Mode Multiple Times

Oct 20, 2013

When you have to write data on a file in binary mode multiple times (without closing the file), is the put pointer left where you ended writing the last time, or do you have to use tellp() or seekp() again and again to make sure you write at the right place?

I would have the same question about the get pointer, does he stay in place after you're done reading something (without closing the file, of course), or do you have to set it back at the right place with seekg() ??

View 5 Replies View Related

C :: Printf Ints That Are Modified In Another Function?

Feb 13, 2013

I have gotten it to record the date and I can printf it either on the same function, or in the main(). However, one of the requirements I must adhere to is to printf the statement in a brand new function, but when I do that, it just doesn't work. Heres what I mean:

Code:

#include <stdio.h>
#define TICKER "LRCX"
#define INVESTMENT_AMOUNT "10,000.00"
//Prototypes
int getdate(int* month1,int* day1,int* year1,int* month2,int* day2,int* year2);
float getprice(float* BPrice, float* SPrice);
void printdate(int month1, int day1, int year1);
}

[code]....

View 3 Replies View Related

C++ :: Passing Ints To Void Functions

Mar 19, 2014

At first i had my int variables in global scope however i cant do the so im trying to pass my variables from my main to the void functions but cant.....

View 1 Replies View Related

C++ :: Generate Lists Of Permutations Of Ints

Jul 26, 2014

I am trying to generate some lists of permutations of ints but I can't make std::next_permutation work for me. The problem is I need to include permutations which don't use every number. For example take the array of numbers [1, 2]. I need an algo that will return:

1
2
12
21

Must work with up to 8 numbers.

View 5 Replies View Related

C++ :: Function That Will Take 3 Ints And Find Sum Of Higher 2

Mar 12, 2014

I am trying to figure out the larger 2 out of 3 integers when i call them into a function from main program so far i have . How to write a simple function that will take 3 ints and find the sum of the higher 2?

Code:

int findsum(int a,int b,int c)// will find the highest int and return it to our main program {
int max,max2;// this sets our local variable max
// next we will find the larger of our first 2 variables
if( a>=b)

[Code]....

How to get the second highest number and add it to max...

View 4 Replies View Related

C/C++ :: Read In String With Multiple Words And Numbers?

Jul 23, 2014

I am trying to read user input for recipe ingredients which must include a ingredient name, and may include a quantity and a unit. Example: Stone ground flour 2 cups or Sugar 1 Tbsp or Milk. The problem I am having is that the string gets cut off after a space when multiple words are used for the ingredient name.

cin.ignore();
string line;
getline(cin, line);
istringstream record(line);
string name;
string name2;
int quantity = 0;
string unit;
record>>name>>quantity>>unit;

View 1 Replies View Related

C/C++ :: Program To Find Min / Max Values Of Two Ints / Doubles And Chars

Jan 31, 2015

I'm supposed to create a program that will find the min/max values of two ints, doubles, and chars, It's not completely done but here's what I have so far.

It's giving me an Error 1 error LNK2019: unresolved external symbol "public: __thiscall MinMax<int>::MinMax<int>(int,int)" (??0?$MinMax@H@@QAE@HH@Z) referenced in function _mainC:UsersDerickDesktopCiss243Week3 Assignment2Week3 Assignment2Main.objWeek3 Assignment2

Header file
#ifndef MINMAX_H
#define MINMAX_H
#include <iostream>
using namespace std;
template <class T>
class MinMax

[Code] ....

I don't know why the site is adding in extra bits of code like /> in certain areas, it's not there when I paste it in and it's not in my code ....

View 5 Replies View Related

C/C++ :: Get Fstream / Ostream / Ifstream To Save Ints Then Load Them

Jun 5, 2014

I have been trying to figure this out for a text based game. Lets say your money is 500. Then you save your game, but when you start the game the starting is 50, so when you load it, you still have 500 money, I tried lots of test, and im having trouble?

View 10 Replies View Related

C/C++ :: Loop To Add Ints / Strings Into Vector In Ascending Order

Feb 24, 2014

The code is supposed to take either an int or a string (and their respective vectors) and insert a given int or string into the vector in ascending order. My code works properly for ints, but it's having a problem with strings.

The order I get with the strings given is

penguin
banana
great
jungle

For some reason comparing penguin to banana/great doesn't give the expected result. The template attached only includes the function and the private vectors needed for the function.

template<class T>
class orderedList {
public:
void insert(const T& item);
private:
vector<T> list;
int total = 0;

[Code] ....

View 11 Replies View Related

C/C++ :: Atoi Does Not Work / Converting Cstring Vector Into Ints

Feb 18, 2015

I have saved the contents of an int vector to a txt file and the numerical data was converted into a c-string. Nov I need to import and read the contents back into my program but I have not been able to convert c-string numerical data back into ints.

View 1 Replies View Related







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