Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. getline(cin, s); issues

getline(cin, s); issues

Scheduled Pinned Locked Moved C / C++ / MFC
helpalgorithmstutorialquestion
1 Posts 1 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RanBlade
    wrote on last edited by
    #1

    I have googled for the last hour and havent found anyhting worth not(most likely because Iam not searching the right terms). Anyway getling(cin, s) is the only way I know of to get a multiple word string pulled together and that will output as it went in. But the problem is you have to hit the enter key twice in order for the program to move on. is there a better way of going about getting a sentence or string of words in one input or is there some kind of function I can use to make it so the person dosent have to hit enter twice? here is the little sample program i have been working with to try and figure this out. #include #include int main() { std::string test, test1; std::cout << "Enter something: "; std::getling(std::cin, test); std::cin.ignore(100, '\n'); // with or without this i have to hit enter twice // this just makes it possible to display another string.. std::cout << test << std::endl; std::cout << "Enter again: "; std::getling(std::cin, test1); std::cout << test1 << std::endl; return 0; } I know this probably isnt the best code for many reasons but Iam just trying to figure out how to make it possible to enter a multi word string. any help would be great as Iam finnally stuck and cant get any furthur on my own. RanBlade aka Eric Ranaldi "Passion is what drive you to stay until 4am ficing that minor bug that hardly anyone would notice...Passion is where great games come from. If you don'l live and breath games, you shouldn't be in the gaming industry" - Dave Pottinger, Ensemble Studios

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups