•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 402,755 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,580 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 1660 | Replies: 2 | Solved
![]() |
•
•
Join Date: Jan 2005
Posts: 15
Reputation:
Rep Power: 4
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.
//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
//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
#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
*/#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
*/![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- 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)
- Java's String Tokenizer (Java)
Other Threads in the C++ Forum
- Previous Thread: OpenGL, help packaging to allow others to run it
- Next Thread: openGL problem



Linear Mode