d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Hi I Have A Simple Question
Prev12
Add Reply New Topic New Poll
Member
Posts: 3,197
Joined: May 4 2013
Gold: 1,457.00
Member
Posts: 1,086
Joined: May 7 2013
Gold: 0.00
Aug 29 2017 12:50am
Quote (nuvo @ Aug 28 2017 10:05am)


No I mean for example if I type in: Hi my name is John Locke
it must then print: Hello John Locke
Member
Posts: 27,177
Joined: Mar 27 2008
Gold: 445.00
Aug 29 2017 05:39am
Quote (John_Locke @ Aug 29 2017 02:50am)
No I mean for example if I type in: Hi my name is John Locke
it must then print: Hello John Locke


Basic structure.

if (stringCompareFunction(variable, "string")==0)
{
do stuff
}

Looked at the function nuvo posted and you can work out any permiation with that structure.
Member
Posts: 23,502
Joined: Aug 3 2011
Gold: 6,921.00
Aug 29 2017 04:40pm
Quote (John_Locke @ Aug 28 2017 12:00pm)
I have many books and they have all thousands of pages and I am looking for long now and still just do not get them.
I am not trying to blindly copypaste I try to understand but for that it must function and then I can learn and put my own content inside.
All I want to know is how can I get a line out of a string compare to use it in the cout.


Oh codeblocks, the most plain IDE ever. Please update to Microsoft visual studios or arduino, implement at the top

Code
using namespace std


If codeblock supports it? Not entirely sure with all the IDEs.
Member
Posts: 5,567
Joined: Apr 30 2006
Gold: 1,020.00
Aug 30 2017 10:54am
Why not use getopt instead? Much better imo than some retarded comparing to specific strings..
Member
Posts: 1,263
Joined: Feb 11 2008
Gold: 2,650.00
Sep 1 2017 12:57am
Quote (John_Locke @ Aug 28 2017 08:44am)


The prefix
Code
std::
means to use the std namespace's definition the item. In the sample code blocks provided, the items prefixed by std:: are defined within the std namespace. It's probably enough for a beginner to know that "std" is a very common namespace that defines a lot of commonly used classes and functions, so you'll see it used often (along with a shortcut "using namespace std" directive). They're more complicated than that, but you can read up on them here:
http://en.cppreference.com/w/cpp/language/namespace

Bool is a primitive data type in C++. That means the compiler knows what it is and how to use it without any includes, classes/structs, or namespaces. Putting
Code
std::bool
tells the compiler to look for a bool type defined in the std namespace, which it cannot find. Take off the std:: prefix and it'll use the default bool data type. More information on C++ primitives here:
http://www.geeksforgeeks.org/c-data-types/

You really ought to be using google to debug these issues. Your code and errors are basic enough that if you key in the exact error message into google it'll usually show you somebody else who had the exact same issue you did.
Member
Posts: 1,039
Joined: Jul 8 2008
Gold: 1,939.50
Sep 2 2017 11:19am
edit: nevermind I didn't see postmortemvox's post.
tl;dr Remove std:: and ask for input instead of calling system pause

This post was edited by waraholic on Sep 2 2017 11:21am
Go Back To Programming & Development Topic List
Prev12
Add Reply New Topic New Poll