how can I read some strings that contains spaces and put them in a vector of strings, using the push_back() function?
I have a collection of functions, for example: [multiply_by_forty two, add_by_five]. All I want to do is to store the strings like: multiply_by, add_by in a vector of strings, and the arguments:forty two, five etc in another vector of strings, but with spaces. The function convert() converts written numbers to numbers (for ex the output of covert("forty two")is 42;)
I have a problem, caught the last line of a file and do the division of the same variables in, date, time and value, but the file contains excess spaces in all lines and the date is coming with cuts, example 24/4/2014 appears 4/4/2014. How can I remove the space in the string without affecting the division of the line?
if (file) { std::string line = getLastLine(file); std::istringstream iss(line); getline(iss, date, ' '); getline(iss, time, ' '); getline(iss, t); //variavel para temperatura em string } else { std::cout << "error file ";
or better yet, what if I want it to not matter whether the columns are separated by commas or spaces? is there any way to do this? If there is no way to read in both comma-separated and space-separated elements simultaneously then I would prefer just comma, rather than the space separated which my code is able to read now. What modifications would I have to make to my code to make this work? This is my code to reference.
i have a string which is n characters long. i need to read say 20 characters at a time, wait for the user to type OK and then send another 20 characters. wait for the user to type OK and send 20 characters again until we get to the nth character.
void login() { //username, password, option to register, option to exit, link to website cout << "Would you like to login(1), or press anything else to register.?" << endl; cin >> loginYorN; if (loginYorN == 1) { cout << "Please enter your username: "; cin >> accountInfo[1];
[code]...
So as above, I ask them to input 1 for login, anything else for register. Whatever they input, it get's stored into loginYorN, then I check to see what they input. If they put '1' for input, then I ask them for their username, store that into accountInfo[1], and then asking for the password, storing that into accountInfo[2].
Now here is where I need to input line 1(username) from login.csv or login.txt and line2(password) and storage these into accountID and accountPW.
I have a problem with transforming a string, for example
"13 + 19"
and store this in a list as seperate integers,
list = {13, 19};
and another list with the +, -, /:
list2 = {+};
this is my function:
int evaluate(char* formula, int* result) { struct List *listofintegers = list_create(); //creates a list, this is the structure: /* struct ListNode { int value; struct ListNode* next;
[Code] ....
This is how i execute my function in my main.c:
int value; evaluate("19 + 16", value);
This is what i get in my prompt:
I will also have to seperate the +, - and / in another list,
I don't even know how i can get my string when char* formula is given as an argument...
wrote this program to check if a string is an integer. It checks for + or - sign at the front of it, but it spat out some errors.I think I broke it.Here is the code:
Code:
#include<stdio.h> #include<ctype.h> #include<stdlib.h> int getInteger(char*); int main(void) { char str[99]; int x; }
This program is suppose to read a matrix file , and the first getline is suppose to get the file header but it appears that 'line' doesn't take in any value other than empty thus causing all the problem , I tried to put cin.getline() in front of it to take away the /n created by the cin before it , but it doesn't work . When I debug the program when the arrow points to the string line , this error appears
line<Error reading characters of string.>std::basic_string<char,std::char_traits<char>,std::allocator<char> >
I tried to initialize string line=NULL too , doesn't work either.
I know how to do this in c++ with fstream and std::string and getline and so on and so forth. Im writing my code solely in c however. I can't get g++ installed so figured it was a good excuse to learn c instead of using the equivalent c++ abstracts.
My problem is, I'm making a game in c that I have made in c++ but have ran into an issue with my map. I want to read in my map from a file which just looks like this: Name of Town * * * * * * * * * * * * * * * * * * * * * etc...
so i tried using fscanf to first read in the name of the town (stored in a char*) then read in the characters (in this case '*')(not including white spaces becuase i can just print those) into another char*. what is the better way to do this?
I am trying to record some information in a file and allow user to delete a record. I am facing this message in Autos section of MVS (Error reading character of string). Here is the code:
int removeRecord(string name, int &row)//remove a record { const string data="database.txt"; fstream records; records.open(data.c_str()); const string cpData="temp.txt";
[code].....
If I delete the any row (except last roe) it works but then add a copy of last record (sometimes fully sometimes partially) at the end of the file!! if i delete the last record it does not do anything.
I am using the code below to write a single instance of object "Employee" to a file in Binary mode. The write part seems to work fine, however when I try to read the single employee object from the file into memory I get a double free or corruption error.
I think this has to do with the fact that I am using a string data member in the Employee class but I don't understand what is going wrong. I have read that strings can vary in length and use dynamic memory allocation but if I write a single employee object to a file with data member 'name' equal to "John", it should be the exact same size when I read it back in right?
The code below works with no issues when I omit the string data member. Why is that? Where is the memory for the string object being "double released" when I read the employee object back into memory from the file?
I am using Linux Mint 15, Eclipse June and GCC 4.7.3 with the -std=c++11 option.
So I am supposed to create a program that reads a file and replaces "<" with "<" , ">" with ">" , "&" with "&" , and " " " with """.........
The program takes a file "test.txt" and reads it, replaces the characters above with the corresponding strings, and then writes the output to "scrubbed.txt".
A sample input would be: <something>
and the output would be: <something>
for some reason I am getting garbage In my new file. What am I doing wrong with the code?
How can I read a file that contains numbers only, but read it by three digits at a time? I have a long string of numbers and every three digits corresponds to a particular number in itself. i.e. a string of 064045154 would need to be read as '064' '045' and '154'. I need to then subtract one from each of these numbers and the new values I need to convert into their ASCII characters and place these in a new file. This is what I have (focusing on the 'Decrypt' function) but all it does is in the new file place a string of the same character repeated over and over a total number of times equal to the number of integers in the numbers file.
I used pointer(or is it not?) to make it one part only alphabets and the other one digits. The coding, calculate_charges.c and the open file, customer.txt are attached at the end of the post.
Code:
#include <stdio.h> #include <string.h> #define SIZE 3 void trimback(char input[], int strnameindex); void trimfrnt(char input[], int strnameindex); }
What would the worst, average and best case space complexity be for a data structure of type map<string, vector<int> > in big O notation? I'm parsing through a document and storing each word as a key and im attaching an associated int (in a vector) to it as the value.
I want the user to be able to enter a command then a character, like for example: push r....I want the command to be stored in the array command, and the character to be stored in the variable c.
Now I wonder what the best way to get rid of the space is, using scanf or getchar (see below for code, only thing that I changed between the 2 versions is the statement before the comment "get rid of space")? Or maybe it doesnt matter?
Code:
include <stdio.h> #define MAX 200 void push(char c); // Puts a new element last in queue char pop(void); // Gets the first element in queue static char s[MAX]; }