|
How can I add elements to the beginning of a vector? I essentially want to merge a vector and a string, putting one ahead of the other. I was going to just take the characters from the string, starting with the end, and add them to the beginning of the vector. Unfortunately, I can only find the push_back function, which adds it to the end. Would it be ok to make the string into a vector, then tack on the other vector? edit: Thanks Milde. Super Dude fucked around with this message at 05:16 on Mar 9, 2008 |
# ¿ Mar 9, 2008 05:06 |
|
|
# ¿ May 3, 2024 18:34 |
|
If I have a vector 'alphabet', and I want to erase a single element at index j, is this the correct syntax? alphabet.erase(j,1);
|
# ¿ Mar 9, 2008 06:13 |
|
using erase(j) gives this error:code:
|
# ¿ Mar 9, 2008 06:27 |
|
(C++)I am trying to grab characters from a string I am reading in from redirecting the cin to a file. Say I have the string "Test" in the file in.txt. I can read the string into my 'string temp' variable. I can write the string to out.txt file as well. My problem is that I want, say, T from the string. cout << temp[0]; It gives me the following error in gedit when I try to open out.txt Could not open the file out.txt gedit has not been able to detect the character encoding. When I cout to the console, it works fine, but it won't work when writing to a file. What am I doing wrong?
|
# ¿ Jan 27, 2009 19:48 |
|
Vanadium posted:Could you post the code and attach in.txt or something? code:
code:
The maps are passed to us in a file (such as the one above). We have to write replicas of the maps with our path to another file. I'm using out.txt. I am running it using: ./proj1 --queue < in.txt > out.txt It gives the error I mentioned in my previous post when I try to access the buildings array to write to my out file. Also, my count variable (which keeps track of the index in the buildings array) gets up to 199 instead of the 192 max for this example.
|
# ¿ Jan 27, 2009 23:03 |
|
Vanadium posted:Can you post the relevant parts of proj1 code:
code:
|
# ¿ Jan 28, 2009 00:15 |
|
Vanadium posted:The ^@ are bytes with value 0. gedit does not know what the hell to do with them. I've never used it, but would cin.flush() get rid of the newline? edit: It seems to be reading that entire first line of the top row of the map as ^@. I've tried cin.flush() and cin.clear(), and neither of those do anything helpful. edit2: I added another getline right after I read in the two numbers, and before I started reading in the rest of the stuff, and that fixed it. That seems like a really crappy way to fix it though. Super Dude fucked around with this message at 02:27 on Jan 28, 2009 |
# ¿ Jan 28, 2009 02:04 |
|
Vanadium posted:You could use std::cin.ignore(std::numeric_limits<int>::max(), '\n'); instead of that getline, or you could just use std::getline in the first place instead of using operator>>, and then use std::strtol or something to read the numbers from the string. But getline grabs it as a string, right? I needed them to be ints.
|
# ¿ Jan 28, 2009 02:49 |
|
Alright I have a quick question that is really annoying me. Say I have a 16 bit number, and I need to get bits 10-13, how do I do this? I was thinking that I could do x >> 10 & 0xD but that isn't working.
|
# ¿ Feb 8, 2009 02:47 |
|
I probably should have explained a little bit better. (I'm using C, so I don't think I can use boost) Say I have the number 01011001 10100011 and I want to get the value for the range in bold (the value 6).
|
# ¿ Feb 8, 2009 03:30 |
|
oldkike posted:You need to shift it right by 10 bits, and then mask off the part you want: Ohhh I get it now. Thanks!
|
# ¿ Feb 8, 2009 03:44 |
|
If I am using freopen(file_name,"r",stdin); to allow me to use "cin >> temp;" to get info from a file, how do I set it back to the 'regular' "cin" from the keyboard after I am done with the file?
|
# ¿ Mar 23, 2009 21:45 |
|
Vanadium posted:You should just create an std::ifstream instead of reopening stdin. I'm not allowed to use ifstream for some stupid reason. Believe me, I would use it if I could. When I try to reopen stdin, and try to read something in, it just skips over it and doesn't read anything. Super Dude fucked around with this message at 23:00 on Mar 23, 2009 |
# ¿ Mar 23, 2009 22:58 |
|
Avenging Dentist posted:Why can't you use ifstreams, and why is using cin an appropriate alternative? Because my prof is the devil. I guess I'm not really sure how to reopen stdin correctly. I'm trying to do this: I run this: ./program data-file.txt In the program I: 1) Use freopen(data-file.txt,"r",stdin); 2) Use while(getline(cin,temp)) to retrieve the data 3) ??? reopen stdin to allow input from the user instead of the file ???? 4) Use while(getline(cin,other_variable)) to get input from the user at the console The program is just skipping over the while loop at step 4 and exiting.(that while loop is the last thing in the program). I don't understand what I need to be doing at step 3 to 'switch input' from the file to the user.
|
# ¿ Mar 24, 2009 00:44 |
|
I doubt he is expecting us to use weird gimmicky solutions. Is there something other than cin and ifstream that I can use to read from a file? Here is the quote from the assignment if that helps to clarify what I am saying: quote:Your program will read from two input streams and write to a single output stream. The database of songs is read from a file named on the command line. All commands are read from standard input. All output (prompts and results of actions) are written to standard output.
|
# ¿ Mar 24, 2009 00:50 |
|
I'm writing some regular expression code in flex, and I'm having a problem. I am trying to detect if there are non-printable characters inbetween a set of < >. For some reason, I can't figure out why my current solution is not working.code:
Any ideas?
|
# ¿ Sep 5, 2011 07:09 |
|
Jabor posted:So what you're attempting to match is: I guess I'm not seeing what I'm missing because from what I see, my regex matches the description.
|
# ¿ Sep 5, 2011 11:42 |
|
|
# ¿ May 3, 2024 18:34 |
|
roomforthetuna posted:Edit2: Also you could have it match the first non-printable more simply with [^>]*? assuming the specific regexp parser supports that "match shortest" semantic. Unfortunately ? isn't supported (flex is stupid). \<([[:print:]]{-}[>\n<])*[^[:print:]][^>]*\> I think this fixed the problem. It looks horrible and is impossible to read, which really pisses me off. Super Dude fucked around with this message at 18:52 on Sep 5, 2011 |
# ¿ Sep 5, 2011 18:44 |