C++ :: Formatted Input Using Cin
Apr 28, 2013
I'm trying to use cin to get input in a specific format.
Say I have this string as an input: "+ Baraq 112540783 AB1234" I want my variables to look like that:
name = "Baraq"
id = 112540783
book = "AB1234"
now I am sure there is something with providing the format of the input " %s %s %s" or something like that, just not sure how to use it.
View 5 Replies
ADVERTISEMENT
Feb 1, 2013
where to start and how it should be structured. how I should go about writing this program, like should i make functions, pointers, etc. And to display the menu, is it easiest to just use printf statements or is there something more efficient.
View 3 Replies
View Related
Nov 27, 2013
reading fasta formatted files. Usually ppl from computation biology know what that is but for those that are not here is a quick guide :
Fasta formatted file:
Code: >header
seqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseq
seqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseq
seqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseq
seqseqseqseqseqseqseqseqseq
>header1
seqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseq
seqseqseqseqseqseqseqseqseqseq
... so a very simple file format. and what i need to do is to read that into memory (vector of strings) so that header info and seq info is in two different vectors. for that i am using the following function :
Code:
sequence and headers vectors are class variables:
template <typename TStr>
template <typename FS>
void FastaSeq<TStr>::ReadFasta(FS& fs){
string line;
string seq;
while (fs >> line){
if(line.c_str()[0] == '>'){
[code].....
this code does what is suppose to do but it is EXTREMELY slow. it takes me exponentially more time to read the seq in memory then to process it. when compared to c style alternative that reads character by character it takes 13 sec with this function to do the same job that my c function does in 0.03 sec. How to improve upon this function to make it comparably fast (also i am using optimization) ?
View 10 Replies
View Related
Aug 9, 2012
my data are
#saben~123~tvm~999999~local~#
#ach~123~tvm~999999~body~#
#sam~123~tvm~999999~wash~#
#sus~123~tvm~999999~area~#
#sach~123~tvm~999999~local~#
View 3 Replies
View Related
Jan 8, 2013
i have an xml which is in showing in multilines and the tags are not in single line and are discontinued in next line .I need to this xml to be in correct format and want to display as xml .
View 1 Replies
View Related
Nov 28, 2014
I wanted to improve the game from my last thread. I want to read and store a question in this format: Code: Who invented the BALLPOINT PEN?
A - Biro Brothers
B - Waterman Brothers
C - Bicc Brothers
D - Write Bothers
But when I use fgets() to read the string, it reads all the ' ' literally instead of outputting a real newline. Like if it read the above question, I want it to print something like this:
Code:
Who invented the BALLPOINT PEN?
A - Biro Brothers
B - Waterman Brothers
C - Bicc Brothers
D - Write Bothers
View 3 Replies
View Related
Feb 22, 2015
1) ask the user to input a mathematical expression in the following format:
NUMBER Operator NUMBER Operator NUMBER
Example: 17 + 15 - 3
Example: 2 * 3 - 4
How to output the answer of the users equation. Is there a function that includes all math operators (+,-,/,*)? Would i need to write each possible scenario using if statements?
View 2 Replies
View Related
Apr 16, 2014
The program is supposed to read a formatted .txt file and store the data into their respective [Class] Members. It will then output the data collected onto screen.I overloaded ifstream and istream. When I call for file>>ptr[i] to read the data, something goes wrong. It prompts me to input data (which is in istream overload).The Data in .txt file is as follows;
#ifndef STUDENTTESTSCORES_H
#define STUDENTTESTSCORES_H
#include <string>
#include <iostream>
#include <fstream>
using namespace std;
[code]....
View 6 Replies
View Related
Oct 13, 2014
Write a program that reads in the numeric representation of a date and prints it out in a formatted manner as the box below.
1. If the user entered an invalid number for the month it should display "Invalid Month"
2. If the user entered an invalid number for the date it should display "Invalid Date"
3. Check to see if the day is outside the range for that particular month
An example of the input and the output:
Enter the date: 1 24 2013
The date you entered is: 1242013
Im not sure on how to go about this problem, but this is what I have.
#include <stdio.h>
int main(void) {
int a, b, c;
int status;
printf("Enter the Date");
status = scanf("%d,%d,%d",&a, &b, &c);
printf(" The Date is : %d",status);
return 0;
}
Am I going about this right? Is there an easier or better way to go about it? All that happens is that the program reads the first number and spits that back out.
View 5 Replies
View Related
Aug 12, 2014
How to append a formatted string to a string. I know printf will print them, but I want to append them. Is there a way to do this. I am doing a little work with pointers, and I seem to have forgotten things like this.
View 2 Replies
View Related
Apr 6, 2013
I am trying to create a simple interface on console to allow to input some values to some variables. For ex:
int main() {
double a = 1.5;
double b = 2.5;
double c = 3.5;
string x;
[Code] ....
However, I want these three to display at the same time (now they display one by one), and in the console window I can move the cursor between input place of a, b and c with "arrow key" of keyboard.
View 2 Replies
View Related
Jun 17, 2014
deal with a failed input stream and type checking input?
I use:
cout << "
Enter a menu option: ";
while(!(cin >> menuGameMode))
{
cin.clear();
while (cin.get() != '
')
continue;
cout << "Enter a menu option: ";
}
Is this the "Best" way to do it?
EDIT: We're assuming input is expecting an int.
View 9 Replies
View Related
Aug 13, 2014
I would just like to know what does
while( (c =getchar())!='
' && c !=EOF );
do ? and how it do it?
I have see it in a example to clear the input buffer for next input through scanf but does not know its working clearly.
it is used in this example :
Code:
#include<stdio.h>
struct linklist {
char value[20];
struct linklist *next;
};
struct linklist *head,*curr;
[Code] .....
View 4 Replies
View Related
Mar 20, 2014
Program is to add two fractions together like so..
This program adds fractions. ‘Y’ continues, any other key exits program
===================================================
Enter numerator 1 ==> 1
Enter denominator 1 ==> 3
Enter numerator 2 ==> 1
Enter denominator 2 ==> 6
1 1 1
--- + --- = ---
3 6 2
-----------------------------------------------------
Continue? Y or N! ==> n
My question is that i need each input to be a number.
if a character is entered i want it to output something like..
This program adds fractions. ‘Y’ continues, any other key exits program
===================================================
Enter numerator 1 ==> 1
Enter denominator 1 ==> a
You need to enter a number here.
Press any key to continue.
and then clear the part where the letter was entered.
This program adds fractions. ‘Y’ continues, any other key exits program
===================================================
Enter numerator 1 ==> 1
Enter denominator 1 ==>
View 5 Replies
View Related
Sep 20, 2014
how to input with space what i mean is like this, for example:
Product Code: 0000001
Product Name: Mobile Phone
if the users input is like that in the (Product Name)it will skip the next input that is the
Price: Quantity: 100
Manufacturer: Alcatel
something like that...
Heres the code
Code:
if(b<=10)
{/*Start for IF Statement*/
for(a=1;a<=b;a++)
{/*Start of FOR loop*/
printf("
");
printf("Product Code : ");
scanf("%s", &prod_code);
}
[code]....
View 14 Replies
View Related
Feb 16, 2013
I brought some code from a PICDEM DV lab example into a simple program I'd written. The example showed how to use the external interrupt on the PIC16F690 to switch directions in a function.
I've been trying to use that RA2 pin as both the input (start) trigger for one of my functions and as an interrupt to get out of that function, too. So far the interrupt doesn't work, but the function trigger does. Should I use two pushbuttons or add a random timer to the for() loop to execute the function to roll the dice?
Trying to incorporate that example code also seems to have messed up the little random counter [a for() loop] that I used. The dice pattern was reliably random before adding this new stuff, and now I can clearly see repetition.
I'm only just starting a MC class.
Code:
#pragma config FOSC = INTRCIO // Oscillator Selection bit
#pragma config WDTE = OFF // Watchdog Timer Enable bit
#pragma config PWRTE = OFF // Power-up Timer Enable bit
[Code].....
View 3 Replies
View Related
Jan 22, 2013
I am trying to make a poker scoring code and am struggling a bit with the 'picture cards'. The user inputs the handfor example 3c 7d 9h js ad.I have worked out nearly all of the source code, except straights that include jack queen king ace.Is there anyway that when a user types in J the code will recognize it as 11, then queen as 12, etc etc. So from there I could still use the same code I have already made.Here is the part of my code that works out the straight.
Code:
#include<stdio.h>
int main(void)
{ int c;
int n;
int count1[127] = {0};
int count2[127] = {0};
}
[code]...
View 5 Replies
View Related
Jan 6, 2014
Is there any way to input a picture into an application? I want to make the console of my C++ program display an image across it for a short while. The picture in mind is a gif. If there is no way to make it display in the console, is there a way to make only the image and not the webpage pop up on the screen?
I am trying to replicate the Skyfall "M gets hacked" scene. But this would be useful for other purposes as well.
I am not familiar with using header files or any other files other than the .cpp file and I only use one .cpp file for all my programs.
View 7 Replies
View Related
May 11, 2013
This is an example from C++ Primer on while loops shortened for simplicity:
int main() {
int value = 0;
while(cin >> value) cout << value;
return 0;
}
When I compile and run the above code the program keeps asking for input after I input nothing but pressing ENTER no matter how many times. The only way I can get it to stop asking for input is to input something other than an int such as a char or string. Program executes as intended after that. I have googled this issue and read all seemingly relevant results and nothing seems to pertain to my exact problem. I think it may have something to do with my computer's own settings or something and am baffled as to what it may be.
View 10 Replies
View Related
Apr 28, 2013
Assignment: Write a program that merges the numbers in two files and writes all the numbers into a third file. your program takes input from two different files and writes it output to a third file. Each input file contains a list of numbers of type int in sorted order from the smallest to largest. after the program is run, the output file will contain all the numbers in the two input files in one longer list in sorted order from smallest to largest. your program should define a function that is called with the two input - file streams and the out - put file stream as three arguments.
Okay, here is my code.
#include<iostream>
#include<fstream>
using namespace std;
int main() {
int list1[25];//array for the first list
int list2[25];//array for the second list
[Code] .....
I'm confused about where the two files (which contain lists of numbers) need to be placed in order to be read and if they need to be renamed or something.
View 1 Replies
View Related
Jan 4, 2015
I want to input only values between 2 - 7 what is wrong?
do{
cout<<"Podaj wykladnik
";
cin>>b;
}while(b<=2 && b>=7);
View 2 Replies
View Related
Sep 9, 2014
I am trying to get the index of a value by inputting the value:
For example if i have
int arr[5]={22, 85, 58, 78, 69};
indexOfItem(arr, 78);
and have the output be:
the index of the item is: 3
View 3 Replies
View Related
Sep 16, 2013
What I want to do is have a defined string as the input and use that to run it against the keys, so I can pull out the values. I have some functions beneath for searching, a possibility would be to parse the input and use something along those lines.
I would like to try and use a map for this.
#include <iostream>
#include <map>
#include <string>
[Code].....
View 6 Replies
View Related
May 12, 2014
So for this function, I'm trying to take an input (may be a user input or an input file) and put that into a variable. The function:
istream & operator>>(istream &is, Event &e)
What direction should I take to implement this?
View 2 Replies
View Related
Dec 5, 2013
How can I put 6 input file into my program.How can I use while to let the 6input file to open automatic?
View 4 Replies
View Related
Mar 26, 2013
So me and my groupmates suddenly have some clutchwork at hand. I was assigned of making an import function that reads through a textfile that looks like this, and store it to a 2D array. Like this [URL]
The columns are Tab-separated however the difference from that image to mine is that i receive a 3x3 matrix with a blank space substituing one of the numbers and i was wondering how could i detect that blank space
View 12 Replies
View Related