| | |
Pressing Enter on an empty string - Help
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Jan 2005
Posts: 15
Reputation:
Solved Threads: 0
Hi all, I'm completly useless at C++ and was wondering if anyone can tell me how to tell a program that when I have pressed Enter, if the string is empty do nothing.
Its for updating details. I'm using an Input header file that my lecturer wrote.
This works fine for updating a student number.
But i am not sure how to do it for a string
I know that LEFT(1) << " " doesn't work. Using == 0 the program works but the fields are empty after updating.
Thanks
Its for updating details. I'm using an Input header file that my lecturer wrote.
This works fine for updating a student number.
C++ Syntax (Toggle Plain Text)
//Amend Student Number cout << "Change Student Number From [" << oldrecord.stuno << "] to: "; Input(tmprecord.stuno); if ( tmprecord.stuno == 0 ) // if return pressed only newrecord.stuno = oldrecord.stuno; else newrecord.stuno = tmprecord.stuno;
But i am not sure how to do it for a string
C++ Syntax (Toggle Plain Text)
//Amend First Name cout << "Change Student First Name From [" << LEFT(21) << oldrecord.firstname.Out << "] to: "; Input(tmprecord.firstname,21); if ( tmprecord.firstname,21 == LEFT(1) << " " ) // if return pressed only newrecord.firstname = oldrecord.firstname; else newrecord.firstname = tmprecord.firstname;
I know that LEFT(1) << " " doesn't work. Using == 0 the program works but the fields are empty after updating.
Thanks
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <string> using namespace std; int main(void) { string text; do { cout << "prompt: "; getline(cin, text); } while ( text[0] == '\0' ); cout << "text = " << text << endl; return 0; } /* my output prompt: prompt: prompt: prompt: hello world text = hello world */
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <string> using namespace std; int main(void) { string text("text"), response(text); do { cout << "prompt <" << text << "> : "; getline(cin, response); } while ( response[0] == '\0' ); text = response; cout << "text = " << text << endl; return 0; } /* my output prompt <text> : prompt <text> : prompt <text> : hello text = hello */
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
![]() |
Similar Threads
- Java's String Tokenizer (Java)
- how to compare a string to null... (C++)
- help me please (JavaScript / DHTML / AJAX)
- Here is the doc file for the assignment (C++)
- continuous string (C)
- passing empty string to SqlCommand.Parameter.Add (VB.NET)
Other Threads in the C++ Forum
- Previous Thread: OpenGL, help packaging to allow others to run it
- Next Thread: openGL problem
Views: 3155 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api array arrays based beginner binary bmp c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete deploy dll download dynamic encryption error file forms fstream function functions game givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib library lines linkedlist linker list loop looping loops map math matrix memory microsoft newbie news number output pointer problem program programming project python random read recursion recursive reference return simple sort spoonfeeding stream string strings struct temperature template templates test text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






