C++ :: Passing Multiple Variable To Function That Has Stringstream And Text
Dec 24, 2013
I have a quick question about passing multiple variable to a func that has (stringstream & text). Here is the code:
void PrintText(stringstream & txt) {
cout << txt.str() << endl;
}
void main() {
[Code] ....
How to make second one work?
View 11 Replies
ADVERTISEMENT
Oct 6, 2014
I have been working on code for quite some time and am able to successfully read in a text document and take certain words and information that I need. The issue is that I need to read in close to 100 plus documents and was wondering how I could read in the multiple documents. I thought about creating a structure of arrays and have each text document be an element and walk through taking each document but I am not sure how this works.
View 8 Replies
View Related
Jun 6, 2013
I build this function in my C++ code. I run the on a UNIX box, build HTML file to use in Windows.
In HTML file building code, I have only a string variable hold the contents of this text file (from unix) & add it into HTML file.
The issue is that when I view the HTML file on windows, it shows all the lines in the text file as one line. I think it lost the CRLF.
My question is when I add lines from text file (reading one line at a time) in UNIX, how do I maintain CRLF ( ) in the stringstream variable so that it will display on HTML in Windows properly, all the lines as it is in unix.
I am aware UNIX uses for line end.
string TextFileToString(string filename) {
string line;
stringstream dosString;
ifstream inFile;
[Code] ......
View 4 Replies
View Related
Dec 17, 2014
Write a program using inheritance allow user to enter grades of his students 5~8 students as a base class and compute the sums for each students in derived class and compute the average of sums in another derived class. I created 3 classes in 1 header file and 1 cpp file how ever i cant seem to get the sum or the average to show up on execution time
header file
#ifndef GRADES_H_INCLUDED
#define GRADES_H_INCLUDED
class Grades {
public:
Grades()
[Code] .....
View 2 Replies
View Related
Nov 8, 2013
This code is for a program that allows you to play a guessing game or arithmetic game and shows your total score from both as you go along. The program works fine the only problem I'm having is with the score. Is there a way to call the score value from the outside function into main?
Code:
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
//prototype functions
void menu();
[Code] .....
So trying to pass the value of score from the outer function int guessGame() into the score print statement in choice 3 of the main function? Oh and the "17 -turn_count" was just part of the requirements of the assignment.
View 6 Replies
View Related
Sep 8, 2014
#include<iostream>
using namespace std;
int main(){
int size_col = 12;
int size_row = 12;
char months_array[12][12] =
[Code] ....
I am having problems with passing a block of a char to a variable, so i could print it out.
It gives me an error: value of type *char cannot be assigned to a entity type char.
View 7 Replies
View Related
May 19, 2014
How can I add integer value to a stringstream or read an integer value from it?
View 1 Replies
View Related
Mar 30, 2014
I have program where i have to check to see if file exist, if it does not then it needs to be created. SO I have a read file that works fine, if th efile exist it reads whats in it, if it does it says the file does not exist. Now Im trying to creata function that creates the file if it doesnt exist. so in my read function when the person enters the name of the file to be checked for..I pass that name to a variable called name..Hoping that I could then pass it into my create file function if it does not exist..and use that variable to pass the name they entered into the createfile array..called filename.. but I am having trouble because i get error when i try to pass from a string name to char array.. even when I change the varialbe name to char, or char [256] it will not work.. I try to fing a way to convert th string to a char using the strncopy function but still no dice..here the code i have for the createfile funciton
void CreateNew(ofstream & FileNew)//Create file
{
char filename[256];
string name;
[Code].....
How can i do this without having to ask the person to enter the file name twice..
View 12 Replies
View Related
Mar 25, 2013
I have create a function which able to return value for variant of variable through a LPVOID parameter function.
Here is my coding.
Code:
void main()
{
CClassA a;
BOOL bAssign=FALSE;
CString str;
[Code].....
View 6 Replies
View Related
Dec 12, 2012
I am attaching a sample project. Basically what this project does is that I initialize a variable map<CString, bool*> m_mapTest in CView::OnInitialUpdate and then pass the variable to CDocument class. On the other hand, within the function OnSaveDocument defined in CDocument I check m_mapTest. To my surprise, the CString part of m_mapTest is correct but the bool* part of m_mapTest is wrong(I pass an array of bool in CView::OnInitialUpdate).
View 3 Replies
View Related
Sep 7, 2013
I was trying out programs based on extern and as i understand, this is useful when accessing variables across multiple files having only one definition. But i tried a simple program as below without "extern" and thing seem to work when i expected it would fail during linking process
Code:
file5.c
1 #include <stdio.h>
2 #include "var.h"
3
4 int main() {
5
6 printf("
File5.c a = %d", a);
[Code] .....
As i have included "var.h" in all header files without extern, "int a" would be included in both the .c file and during linking, compiler should have thrown a warning or error message but it compiles file without any issue. Shouldn't var.h have the following "extern int a"?
View 8 Replies
View Related
Mar 9, 2013
In the existing code,fork has call parallel to create process.my job is to store all the process id into vector so that we can verify the status of the jobs. I was able to save all the jobs but as the callback happen so I have lost my all value which was store into vector.
How can i maintain variable between multiple process.
View 1 Replies
View Related
Feb 13, 2013
I'd like to know what happens if I use multiple calls to malloc() on one pointer (without free) in a single function. Here is the example:
void *data_thread(void *sockfd_ptr) {
int sockfd = *(int *) sockfd_ptr;
const int BUFSIZE = 5;
char recvmessage[BUFSIZE];
char *headerstr = NULL;
char *newheaderstr = NULL;
[code]....
what happens with newheaderstr every time malloc() is called. There isn't a realloc() or anything. I didn't think it looked right to keep using malloc() like that.
View 4 Replies
View Related
Aug 31, 2014
So I have a class object that contains the private member variable spot and the public member function MoveLock. Within MoveLock, is a member variable called numbers that holds the place where a user is on a "lock knob". Now, what I'm trying to accomplish is that whenever the user turns the "knob" in the wrong direction, the position is updated with that current numbers so that the clicks needed to unlock the first state is also updated. But I get these errors:
Error E2096 C:Users...switchtest.cpp 34: Illegal structure operation in function main()
Error E2294 C:Users...switchtest.cpp 39: Structure required on left side of . or .* in function main()
Ultimately, what I have in main() is a piece of what I'm going to implement in a class member function. I'm also thinking about moving the if else statements out of the for and creating a second one for the else portion.
#include <iostream>
#include <windows.h>
#include <iomanip>
using namespace std;
HANDLE inKeys = GetStdHandle(STD_INPUT_HANDLE);
HANDLE screen = GetStdHandle(STD_OUTPUT_HANDLE);
[code]....
View 10 Replies
View Related
Dec 21, 2014
I just wanna have a very simple function that reads values from a text file row by row. The first value is passed along from the stringstream to my float data[] but after that it doesn't pass along anything. The strange part (for me at least) is that the stringstream contains the values it should contain, but they doesn't wanna end up in data[].
main.cpp
#include <fstream>
#include <iostream>
#include <string>
#include <sstream>
[Code]....
View 4 Replies
View Related
Oct 29, 2014
I tried to create a multiple choice list and I want to assign the value of the answer option chosen by the user so I can use it later on in the code. Later on in the code i've asked how many people (p) want a drink and multiplied it by the chosen size to calculate the price c = p * n where c is cost, n is price and p is number o of people At the bottom i tried to assign parameters where depending on what option the user has chosen n will be assigned to the chosen value...
{
printf("SELECT TYPE OF PAINT:"); /*multiple choice of paint */
printf("1. Large ");
[Code]....
View 1 Replies
View Related
Jul 1, 2013
I have a std::stringstream sstr I read data from with getline(sstr, s, ',').
Now I don't want it to cut off the leading blanks. How can I do that?
View 2 Replies
View Related
Oct 1, 2013
So I have a text file named test.txt on the root of my c:/drive.
I finally managed to arrays working and reading into them, but when I started looking at the data in the array I noticed that stringstream was not "grabbing" a specified space. LINES 83-88
The text file contains the following (note that there is an intentional space after the first word):
I ' m s o r 0 y 4 D a v e , 5 12 12 12 3 7 f 11 2 i d 5 8 1 c 5 n 10 t 5 7 17 2 3 h 7 2 .
I need that space to be caught in the steam, there will always be only one space after a various first word, but I need it in my array and stringstream doesn't catch it.
if you need to run it, just copy the text to a file named c:/test.txt
When you run the code, you will see after the 3rd iteration it skips the space, is there a way to change this, so I can focus on the decryption algorithm??
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <stdio.h>
#include <sstream>
#include <cctype>
bool is_number(const std::string& s){
std::string::const_iterator it = s.begin();
[Code] ...
View 13 Replies
View Related
Apr 20, 2014
I trying to get input from the user and split into words that separated by a space.
string s = "1 2 3";
istringstream iss(s);
int n;
while (iss >> n) {
cout << "* " << n << endl;
}
The code above works fine but i want to get the string from user. the code below only prints the first word and trashes rest of the words in the sentence.
string s ;
cin>>s;
istringstream iss(s);
string n;
while (iss >> n) {
cout << "* " << n << endl;
}
View 2 Replies
View Related
May 24, 2013
I'm trying to passing values from a text file to an array. The values in txt file is;
0 2 3 5
1 2 5
0 1 3 6
1 3 5
I need to store these values in an array like that
Code:
int array[?][?]={{0,2,3,5},{1,2,5},{0,1,3,6},{1,3,5}};
View 1 Replies
View Related
May 31, 2013
I want to know how to read multiple text files in this program... I have 5 text files(order1,order2,...order5).
#include<iostream.h>
#include<fstream.h>
#include<conio.h>
#include<windows.h>
using namespace std;
class{
[Code] ....
View 3 Replies
View Related
Jan 21, 2014
private void open(object sender, EventArgs e)
{
// only works for opening the table
dataGridView1.Rows.Clear();
[Code]....
So here in my open method I get a dialog on the file to open and it will display all the saved data into a DataGridView. Every cell is separated by a comma. It will work fine and there are no errors.
However, I'm looking to upgrade this into importing data into another DataGridView instead.
Now all this opening is based off of the writing code not manually written. The writing part is complete with dataGridView1 and dataGridView2 written. However, how do I determine if the data is going to be written in the first or second DGV?
View 6 Replies
View Related
Oct 15, 2013
I want to store few different functions to a variable for different structs/classes and then call it later using that variable, is it possible? something like
struct item {
int ID;
int special; // for function
};
item Key;
Key.special = UseKey(KEY_KING);
// now when I want to call function "UseKey(KEY_KING)" I want to use "Key.special", like this
if(iCurrRoom == ROOM_KING)
Key.special;
else if(iCurrRoom == ROOM_DRAGON)
Fireball.special;
View 5 Replies
View Related
Jan 31, 2014
I am trying to make a messageBoxButtons dialog with the 'yes, no' buttons. Im having trouble because of the multiple lines and parameters already in the message, this means that when i declare the messageBoxButtons.YesNo and the title - it throws an error because of the multiple lines etc...
How can I get the yes/no message box to work in this instance?
class Output {
string text; {
DialogResult dialogResult = MessageBox.Show("Please make sure the following information is correct before submitting."
+ " Date: " + Date
+ " Hours worked: " + Hours
+ " Hourly rate: $" + Rate
[Code] ....
View 5 Replies
View Related
Jun 8, 2013
I am supposed to read(scan) data from a folder with multiple(21578) text files, and file names are numbered from 1 to 21578,and read each word that occurs in a text file, and count the number of times it occurs in the entire folder,i.e; in all the files how do i go about it? I've tried this so far..but it isn't working..
#include <iostream>
#include <map>
#include <string>
using namespace std;
void incrementString(map<string, int> &theMap, string &theString) {
if(theMap.count(theString)) {
[Code] ....
View 1 Replies
View Related
Aug 20, 2013
I want to use one median function "selectfunction" to choose one of the 2 other functions at random to pass my 2-dim array to the selected function. There is a problem in the median function
#include <iostream>
#define random(x)(rand()%x) // for random number between numbers of 0 and 1
using namespace std;
void proc1 (int iArray[][2]);
void proc2 (int iArray[][2]);
void selectfunction(int iArray[][2]);
int A[4][2] = {{1, 2} , {3, 4} , { 5, 7} , {8, 1} };
[Code]...
View 1 Replies
View Related