C/C++ :: Printing A Map That Contains A String And A Class With Integers?
Dec 14, 2014
I'm new to c++, so how to print the contents of a map that contains a string and a class of integers for option 1. what formatting should I use?
#include <iomanip>
#include <vector>
#include <sstream>
#include <map>
#include "IPHost.h"
#include "EncryptedConnection.h"
[Code] .....
View 6 Replies
ADVERTISEMENT
Feb 28, 2013
The program requires the user to enter 10 integers then print the total no. of even integer,highest even integer, lowest even integer then total no. of odd integer,highest odd integer, lowest odd integer
I already got the total no. of even integer and total no. of odd integer. But I don't know how will i get the highest even integer, lowest even integer and highest odd integer, lowest odd integer.
View 2 Replies
View Related
Feb 23, 2015
I have been skimming and searching but dont know how to word the search just right to find what I need to know. I have written simple stuff with the support of tutorials like weight conversion or loops counting up to a set number. Nothing amazing. The other day I found out how to input and print a string rather than a single text character which i though was bad ass. I even got it to read multiple strings on a single line and found a way to read multiple lines. I can even format it to read both integers and characters on the same line as long as I know the predefined format.
On to my question... How do I read multiple lines with both carecters and integers. for instance:
nissan 1996
toyota 1998
or more comples like
nissan gtr 1996
toyota markii 1998
I want to use
int year;
char make[10]; maybe need to use char make[10][10]; for an array i would guess.
char model[10]; optional for the extra data
but reproduce what i read in a different order. say...
1996 nissan
1998 toyota
vice the original format.
this is what I have tried.
Code: scanf("%s %s", &make,&year);
//The way I seen to read multiple lines was on here
scanf("%[^/t]", %make);
But this wont let me separate the two into two differnet definded data types. Let alone use printf to display them in reverse order.
View 1 Replies
View Related
Aug 15, 2014
I'm stuck on printing my grid from my class file to the main file.If I pull out the print code and put in on the actual main program, it prints, but if I try to put in the class methods and call the function from main, I get an error.
testfile.cpp
#include <iostream>
#include <vector>
#include <string>
#include "DUPoint.h"
#include "Grid.h"
using namespace std;
[code]....
View 3 Replies
View Related
Mar 30, 2014
I have created a template class called Queue that stores elements using linked list. I have also created a new type called Date.is there any way to output Date date using Queue functions?
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
template <typename T> struct node{
T value;
node<T> *next;
[code]....
View 3 Replies
View Related
Aug 24, 2013
these are the errors that I'm getting from an online c++ compiler
// main.cpp:4:10: error: #include expects "FILENAME" or
// main.cpp: In function 'void permute(char*, int)':
// main.cpp:17:9: error: 'f' was not declared in this scope
I don't understand how to print full_string to a file!// otherwise, I know that it gives the correct output -- 90 strings.
#include <string>
#include <iostream>
#include <fstream>
#include >ios> // line 4 error
using namespace std;
char full_string[] = "112233";
[code]....
//iter_swap – it just swaps the elements pointed to by the respective pointers without changing the pointers themselves. so, it's basically equivalent to the function:
void iter_swap(char *ptr1, char *ptr2) {
char tmp = *ptr1; *ptr1 = *ptr2;
*ptr2 = tmp;
}
// min_element – finds the location of the minimum element that exists in the given range. in this case,
it is the char* pointer pointing to the location of that element. it can be implemented like:
char *min_element(char *start, char *end) {
// end is 1 beyond the last valid element
if(start == end) return end; // empty range
char *min_pos = start;
for(char *iter = start+1; iter != end; ++iter)
[code]....
View 7 Replies
View Related
Dec 26, 2013
Code:
#include <iostream>
#include <string>
using namespace std;
int main() {
string s="Last Assignment/n";
cout<<j[1]<<j[2]<<j[3];
I don't understand how it printing each element of whole string. Like L a s. But I did not declared array.
View 2 Replies
View Related
Nov 18, 2014
Ok so I have a class that takes integer fractions and I want it to be able to take doubles also depending on what the user inputs. How would I go about this? I was thinking templates ...
View 7 Replies
View Related
Dec 3, 2013
I am doing a program and i need to read integers that are in a string and i dont know if i am doing it correctly.
Code:
unsigned int j=0, h1;
char num[100] , str1[100], str2[100], a[100], b[100];
sscanf(str1, "%[^;] ; %[^;] ; %d ", a, b, &h1); the string is : "0048915433190;24/10/2013;13h 7m 47s;13h 8m 59s;0;1;"
And what i want to read with sscanf is the hours, minutes and seconds.
View 1 Replies
View Related
May 24, 2014
I'm having trouble printing the text in between separators like commas, periods, and at signs. I'm following Jumping into C++ Chapter 19 Practice Problem 2.
This is what I have so far:
Code:
#include <iostream>#include <string>
usingnamespacestd;
int findNeedle (char separator, string inputLine) {
int needleAppearences = 0;
[Code] ....
And this was my test run output:
Enter the contact info. one, two, three, ,? , one two, th three, Program ended with exit code: 0
View 4 Replies
View Related
Jan 25, 2013
Code:
#include<stdio.h>
#include<string.h>
#define a 15
[Code]....
I am trying to print all combinations of a string but I couldn't figure out how to do loop for it. Code works only 2-3-4 letters words
View 4 Replies
View Related
Jan 3, 2015
I am trying to save 5 persons names to a struct, and then printing them afterwards, shortly before the program ends. I tried to print the char string out right after it has been copied over, and it showed fine, but when i try to write it out right at the end of the program (its in a separate function) the terminal just prints gibberish.
the function looks like this:
Code:
int printUser(){
printf("Following patients have been recorded in this session:
");
struct database patient1;
struct database patient2;
struct database patient3;
[Code]...
the output looks like this(as you can se in under structest, that it shows the correct string, it also uses printf):
View 7 Replies
View Related
May 27, 2014
So I have an array of char called s.This array has many words inside, each one separated by ''.The words are sorted by length (from bigger to smaller).I have have a char matrix with random things inside (it was not initialized) caled mat.I want to copy the first word from the array s to the matrix mat.
Code:
int nlin, ncol; /*number of lines and collumns.*/
int c,l,a,q;
char mat [1000][1000];
char s[1000];
}
[code]....
I can't see where this is wrong, but, when i test it, it clearly is not right. for example, if the input is 3 lines and 3 columns for the matrix and the word is crate, the output is :
cra
t
e
but it should be:
cra
t
e
View 11 Replies
View Related
Feb 17, 2013
I am trying to write a program for printing all the combinations of a string. Why this program is giving the error message.
"First-chance exception at 0x761bc41f in word.exe: Microsoft C++ exception: std::out_of_range at memory location 0x0026f6b4..
Unhandled exception at 0x761bc41f in word.exe: Microsoft C++ exception: std::out_of_range at memory location 0x0026f6b4.." when i try to run this in MVS 2010
#include<iostream>
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include<conio.h>
void combination(std::string input,int length,std::string buffer,int allowedno)
[Code] .....
View 1 Replies
View Related
May 14, 2014
How to print a string in reverse order(for example: "today is Wednesday " to "Wednesday is today"). My professor said we should begin with a null string and build it one word at a time.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int nwords(string);
[Code] .....
View 1 Replies
View Related
Feb 21, 2015
i couldnt solve the algorithm exactly. The program asks the user for a string. "Bugun h@v@ cok g'uzel" for example. then the program asks for another string. If that string doesnt exists in the main string program should say there isnt any substring. If it exist then the program should print the remaining part of main string. For example:
Write the first string: Tod@y weather is be'@utiful
write the substring : ug
>>ugun h@v@ cok guzel
write the substring :wldnqwbdbj
>>there isnt any substring
Here where i came so far
#include <stdio.h>
int main()
{
char mainstr[50],substr[50];
[Code]....
View 7 Replies
View Related
Feb 23, 2015
I'm reading in a string from the command line into a char array followed by a series of ints which are read into an int array.
The command line
Code: lab3 word word word 0 0 2 3 results in the following output:
Code: Word: .N=▒
Number of Words: 0
Word: .N=▒word word word
Number of Words: 3
Num: 0
Num: 0
Num: 2
Num: 3
Here is the source code:
int main(int argc, char *argv[]){
if(argc < 2){
//command line must have at least three arguments (one
//char, one integer)
printf("Error: invalid number of arguments
[Code] .....
Where is the .N=▒ coming from?
View 3 Replies
View Related
Jan 27, 2014
For the last part of this problem, if player 2 loses the game of hangman, I need to display the letters they did get right. In order to do that, I believe that I need to traverse vector v for the elements that exist in the string hiddenword, and then print those characters that match.
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int letterFill (char, string, string&);
[Code] ....
View 1 Replies
View Related
Mar 2, 2014
I know strings are essentially just arrays of characters, so what would be the easiest way to take each individual digit and put it into a separate space in an array?
ex.) *str = "90210"
array[0] = 9
array[1] = 0
array[2] = 2
array[3] = 1
array[4] = 0
All my attempts at achieving this just result in an array full of garbage numbers. What I've done is
Code:
int *array;
array = malloc(sizeof(int)*(strlen(str));
for(i=0; i<strlen(str); i++) {
array[i] = str[i]
}
also, I should mention that the string will be defined in main, and its converted into an array in a separate function.
View 2 Replies
View Related
Dec 12, 2013
I'm very very new to maps and am really just trying to hash them out by myself.
If you're mapping strings to integers:
map <string, int> myMap;
myMap[ "zero" ] = 0;
myMap[ "one" ] = 1;
How do I print the string "zero", for instance, from myMap?
cout << myMap.at(0) << endl;
doesn't work. Nor does:
cout << static_cast<string>( myMap.at(0) ) << endl;
I need access to the string using the int and the int using the string. Or just direct access to one or the other. . . It's just confusing that they're technically mapped to one another but I can't really access either of them.
View 4 Replies
View Related
Mar 2, 2014
In my program, I am fed a string that contains integers such as Code: *str = "45678" and my program is simply supposed to read the number in and store each given number in a separate spot in an integer array. So basically, when my program has finished running it should be stored like:
Code:
arr[0] = 4
arr[1] = 5
arr[2] = 6
arr[3] = 7
arr[4] = 8
The way I have been attempting to do this was just copying it to the array like so:
Code:
arr = malloc(sizeof(int) *(strlen(str));
for (i=0; i<strlen(str); i++) {
a->digits[i] = str[i];
}
however, this just seems to return an impossibly high garbage value when I do. I'm assuming the way I'm trying to store it is 'illegal', but I cant seem to find online a proper way to do it.
View 2 Replies
View Related
Sep 21, 2014
char intToStr(int a) {
int n, i, j, sign, set;
char r[10], s[10];
if (a[0] == '-')
sign = -1;
if (sign == -1)
[Code] ....
I have doubt at the time of handling of negative numbers at the time of converting to string ....
View 2 Replies
View Related
Apr 21, 2014
I'm a beginner at c++ and I need to write a program that reads a set of integers and then finds and prints the sum of the even and odd integers. The program cannot tell the user how many integers to enter. I need to have separate totals for the even and odd numbers. what would I need to use so that I can read whatever number of values the user inputs and get the sum of even and odd?
View 2 Replies
View Related
Feb 5, 2013
A string class that finds a char in the string?
View 1 Replies
View Related
Jun 10, 2014
I have to compare the last value of 2 classes The 1rst is a notification class and the 2nd is a message class I have to remember the last value of each of them to compare them ( to not show message if dupplicate text in notification ) I have try to add a new string to memorize the last value in those 2 classes but that doesn't work , I always have nothing in my strings
Here are the points I have add to do it :
- Add declaration memorize strings in both xxxxx.h and yyyyy.h
- Add declaration functions SetMemo and GetMemo in both xxxxx.cpp and yyyyy.cpp
- Add functions source code SetMemo and GetMemo in both xxxxx.cpp and yyyyy.cpp
I have tested step by step :
- The SetMemo works well , it takes the value and save it in memorize string
- The GetMemo works too , take memo string and returns it but the value is empty
I use to develop with C# ... I'm not a C++ expert , maybe I forget something special in C++
View 2 Replies
View Related
May 12, 2013
I have defined a class in a header file; just the class, no templates involved. I have a program where I'm reading in data in string format. Each string consists of a word, a delimiter, and a variable name. Example:
cajun/mustard
I want to take that string and make it the variable name of that class type. It would be implemented along the lines of:
Code:
string str;
//read/process string here, get:
str = "mustard";
createName(str);
//pass string to creator function When the function is called, I should get the variable:
Class mustard;
Thing is, I'm not supposed to know beforehand what the variable names are, only that I create them as they are read in. It could be mustard, it could be Maynard_James_Keenan, it could even be bazinga.
My problem is, what do I do for createName()? I've looked into the concepts of pairing, Factory implementation, and maps, but I don't think they answer my question.
(P.S. if I run into the same variable name being read in twice, what steps can I take to make sure that a duplicate variable isn't created? Do I need to add in code, or does the compiler know to watch for multiple variables of the same name?)
View 6 Replies
View Related