expected ';' before string constant

hello friends,
i am a absolute beginner in c++, and i have started learning c++ using code blocks. i was writing a code that just add two numbers.

the code is:

1
2
3
4
5
6
7
8
9
  #include <iostream>
int main ( )
{
std::cout << " enter two numbers: " << std::endl ;
int v1 , v2 ;
std::cin >> v1 >> v2 ;
std::cout << "the sum of" << v1 "and" << v2 "is" << v1 + v2 << std::endl ;
return 0 ;
}


when i try to compile the code, it shows an error 'expected ';' before string constant' in line 7.

i had wasted an hour in this but unable to find any error
any help would be appreciated.
closed account (o3hC5Di1)
Hi there,

You are forgetting to put the insertion operator << in between v1 and "and":

1
2
3
std::cout << "the sum of" << v1 "and" << v2 "is" << v1 + v2 << std::endl ;
//Should be
std::cout << "the sum of" << v1 << "and" << v2 << "is" << v1 + v2 << std::endl ;


Any text in between double quotes: "This is a string constant" is referred to as a string constant. String because it is a sequence of alphanumerical characters, constant because you cannot change that text, because it is hard coded in the program-code.

All the best,
NwN
It looks like you're missing a set of << between v1 and "and", and v2 and "is".
thanks NwN and jlb it really fixed the problem, thanks so much.
Topic archived. No new replies allowed.