Doing well in classes is important, but is not the only factor that will be used in an admissions decision.
Performance in undergraduate coursework correlates with success in graduate school. Take advantage of tutoring. Form study groups. Attend office hours with your professors. In addition to getting extra exposure to the materials, office hours can help you to establish a personal connection with your professors. These connections can pay dividends when it comes to looking for faculty that can write strong letters of recommendation for your graduate school applications.
At the same time, it is important to recognize that your GPA is only one of many factors that will be used to assess applicants for graduate school admission. A 4.0 GPA is not needed (or expected). Most admissions committees use a holistic process to evaluate applicants. This means that they will consider research experience, leadership, awards, and (many) other factors beyond GPA. If you feel that your undergraduate grades are not representative of your true capabilities, feel free to mention this in your personal statement. Contact the admissions officer(s) at the schools you are considering to discuss how undergraduate grades will be used, and to ask for advice on how you can make your application as strong as possible.