problem with code

#include<iostream>
#include<string>
using namespace std;
int main()
{
char a[10000],b[100];
cout << "enter the string.";
cin >> a;
cout << "enter the string to find";
cin >> b;
int n=a.find(b);
cout << n << "\n";
}
when i use string instead of char and then i enter this is
then this i s considered the first and is the second value
a is a char array and arrays don't have any member functions like find(). That is one of the benefits of using std::string rather than a char array.
still the same porblem
I think you can't even enter the char array this way either:
1
2
3
char a[10000],b[100];
cout << "enter the string.";
cin >> a;


I think you need to enter each element of the array alone. In this case a is the pointer to the first element of array a[10000], so you need a syntax like a[i] or *(a+i) to get the elements of the array. Use string instead unless you have a good reason to use an array of chars.
i dont want a array i want i string
but when i use std::string or string
and enter this
this is
then this is considered a and is b
If you want to use a std::string then std::getline() may be what you're looking for:
1
2
3
std::string a, b;

std::getline(std::cin, a);
it works thanks , thansk to all
i am new to c++ can you tell me how to create a onkeyup function like we do in javascript
That's gonna be a lot trickier. Working with hardware and drivers and stuff can be a pain. I'm pretty sure SFML has a uparrow function, so give that a try: http://www.sfml-dev.org/
That's gonna be a lot trickier. Working with hardware and drivers and stuff can be a pain.
i cant get in c++ can we make radio buttons checkboxes input fields are they dificult
The internet has exabytes of information. Googling something takes about 5 seconds. Go and do some research!
http://www.google.com
Last edited on
ok nice idea
Topic archived. No new replies allowed.