Thread: Can't get the strings into a vector correctly

  1. #1
    Hail to the king, baby. Akkernight's Avatar
    Join Date
    Oct 2008
    Location
    Faroe Islands
    Posts
    717

    Can't get the strings into a vector correctly

    Well I have this:

    Code:
    int main(){
    
    	cout<<"Please input a string: ";
    
    	vector<string> inputVec;
    	string input;
    
    	while(cin>> input)
    		inputVec.push_back(input);
    
    	//vector<string> leftVec = frame(inputVec);
    	//vector<string> picture = vcat(inputVec, leftVec);
    
    	for(vector<string>::size_type i = 0; i != inputVec.size(); ++i)
    		cout<< inputVec[i] <<endl;
    
    	return 0;
    }
    and when I type something in, it only gets the first character, or if it's many words, then it gets as many characters as words, from the first word only... So, is my brain not functioning correctly? 'Cause I've done this quite alot of times, and this time it fails :P
    Last edited by Akkernight; 12-07-2008 at 04:06 PM. Reason: Changed the code
    Currently research OpenGL

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    There's no problem with inputVec. I don't know what frame or vcat do, so I can't say about that. (Or at least if I use your code, then inputVec contains each word in turn, not just a single letter.)

  3. #3
    Hail to the king, baby. Akkernight's Avatar
    Join Date
    Oct 2008
    Location
    Faroe Islands
    Posts
    717
    The frame and vcat are not important at this point :P I'm using VS2008, and when I try Ctrl+C to get past the while loop, it gives me, if I type in "Cookies rule" I get "Coo^C" ...
    Last edited by Akkernight; 12-07-2008 at 04:07 PM.
    Currently research OpenGL

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Since your loop loops until EOF, you need to use EOF to end the loop. On a Win system, EOF is Ctrl-Z.

  5. #5
    Hail to the king, baby. Akkernight's Avatar
    Join Date
    Oct 2008
    Location
    Faroe Islands
    Posts
    717
    Woops! >.< Yeah, I knew that :P
    Currently research OpenGL

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strings Program
    By limergal in forum C++ Programming
    Replies: 4
    Last Post: 12-02-2006, 03:24 PM
  2. Programming using strings
    By jlu0418 in forum C++ Programming
    Replies: 5
    Last Post: 11-26-2006, 08:07 PM
  3. Reading strings input by the user...
    By Cmuppet in forum C Programming
    Replies: 13
    Last Post: 07-21-2004, 06:37 AM
  4. damn strings
    By jmzl666 in forum C Programming
    Replies: 10
    Last Post: 06-24-2002, 02:09 AM
  5. menus and strings
    By garycastillo in forum C Programming
    Replies: 3
    Last Post: 04-29-2002, 11:23 AM

Tags for this Thread