Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9147255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:56:37+00:00 2026-06-17T10:56:37+00:00

I am refreshing my self on C++ (have not did it since school) and

  • 0

I am refreshing my self on C++ (have not did it since school) and I wrote a simple program just to mess around. My problem is when I compile the program it chokes stating
“error: expected initializer before ‘stringThing'”
is there a reason why this is doing this? I know this may be a noob question so I checked stackoverflow and could not find any relevant questions that gave me a answer.

*I am using GNU GCC compiler

Code:

#include <iostream>

using namespace std;

void string stringThing (string shiftdir, string &teststring)
    {
        if (shiftdir == "right")
        {
           teststring = teststring >> " " >> "Bit Shifted right";
        }
        else
        {
           teststring = teststring << " " << "Bit Shifted left";
        }
    }
int main()
{

    string test;

    cout << stringThing("right", "I have done a ") << endl;

    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T10:56:39+00:00Added an answer on June 17, 2026 at 10:56 am

    The return type for stringThing must be either void or string, not both. You also must include <string>, if you want to use string.

    Since you want to output the return value of stringThing() in main, I guess it should be

    std::string stringThing (std::string shiftdir, const std::string &teststring)
    

    But then, you must also return a string from your function

    if (shiftdir == "right")
        return teststring + " " + "Bit Shifted right";
    else
        return teststring + " " + "Bit Shifted left";
    

    for example.

    Your parameter std::string &teststring won’t work with your const char* argument. So either declare it as a copy by value string only, or better const string&.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem refreshing a ListView. I call my ListView Activity , I
I'm using EJB3 and I have a problem related to refreshing my EntityManager .
I am just refreshing the oops features of the java. So, I have a
I have been unable to figure out this problem - it just doesn't make
Being self taught I have not learned everything there is to know about Excel
I'm refreshing my PHP knowledge and have a problem I can't solve on my
I have read many topics about UITableViews not refreshing on iPhone, but couldn't find
I have the problem in refreshing the table. I create the table like this
I'm having problems refreshing .Net 2.0 with IIS 6. I have been able to
I was just refreshing my JavaScript/Jquery skills and I thought of making a basic

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.