Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I have a template function makeMatrix(), code is:
template<size_t N>
void makeMatrix(string dataFilePath, int adjcMatrix[N][N])
{
fstreamExtension fe("adj.txt", ios::in|ios::binary);
string s;
vector<int> temp;
int i = 0;
while(!fe.eof())
{
getline(fe, s);
temp = tokenizeToInt(s, ",\n")); //error: expected ';' before ')' token|
for(int j = 0; j < N; j++)
adjcMatrix[i][j] = temp[j];
i += 1;
}
}
fstreamExtension is a class I created and is included in program through header
#include "fstreamExtension.h", other included headers are iostream string and boost/tokenizer.hpp.
code for tokenizeToInt():
vector<int> tokenizeToInt(string& intString, const char* seperators)
{
vector<int> intValues;
boost::char_separator<char> delims(seperators);
boost::tokenizer<boost::char_separator<char>> tokens(intString, delims);
for (const auto& t : tokens) {
intValues.push_back(atoi(t.c_str()));
}
return intValues;
}
Why it is causing a compilation error in the makeMatrix(), the syntax seems correct, I didn't called it in main(), was compiling some other code then this error popped up when I started a build.
IDE : codeblocks 16.01, gcc.
You should listen to what the compiler tells you. Often the error is simpler than you think:
temp = tokenizeToInt(s, ",\n")); //error: expected ';' before ')' token|
An extra right-parenthesis. The compiler error means "I thought you were done with this command, why are you trying to close another parenthesis-pair?"
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 days ago.
Improve this question
New to C++ here, following outdated training videos...
Trying to compile this simple code, but getting the below error:
#include <iostream>
int main(){
auto result = (10 <=> 20) > 0;
std::cout << result << std::endl;
}
Error I get is:
prog.cc: In function 'int main()':
prog.cc:4:25: error: expected primary-expression before '>' token
4 | auto result = (10 <=> 20) > 0;
|
What am I doing wrong?
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I am new in C++ and i have a little error in this program "Hello world"
//ejemplo funciones definidas por el usuario
#include<iostream>
using namespace std;
int visualizar();
int main()
{
visualizar();
return 0;
}
void visualizar() //Here is the error
{
cout<<"Hola mundo guay\n";
}
Error:
C:\Users\lisan\OneDrive\Desktop\c++\EjemploFunciones.cpp In function 'void visualizar()':
15 17 C:\Users\lisan\OneDrive\Desktop\c++\EjemploFunciones.cpp [Error] ambiguating new declaration of 'void visualizar()'
6 5 C:\Users\lisan\OneDrive\Desktop\c++\EjemploFunciones.cpp [Note] old declaration 'int visualizar()'
What does this error mean? What caused it? How do I fix it?
In your prototype of visualizar, you declared it as
int visualizar();
However, when you defined it, you wrote
void visualizar() { ... }
Notice that the return types are different. Did you mean to use void throughout?
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I have some code, it's quite large so I'll just create a snapshot of it here:
int l = 3;
vector<int> weights;
void changeWeights(int out){
for (int i = 0; i < weights.size(); i++){
int w = std::stoi(std::to_string(weights[i])) -
out*std::stoi(std::to_string(weights[i]));
if (w < -l){
w = -l;
} else if(w > l){
w = l;
}
weights.assign(i, w);
}
}
I get errors on both the 'stoi' and 'to_string' function calls in the form of
Main.cpp:35:21: error: ‘stoi’ is not a member of ‘std’
int w = std::stoi(std::to_string(weights[i])) -
^
Main.cpp:35:31: error: ‘to_string’ is not a member of ‘std’
int w = std::stoi(std::to_string(weights[i])) -
^
Main.cpp:36:17: error: ‘stoi’ is not a member of ‘std’
out*std::stoi(std::to_string(weights[i]));
^
Main.cpp:36:27: error: ‘to_string’ is not a member of ‘std’
out*std::stoi(std::to_string(weights[i]));
I have read some similar queries whereby the answer was to add in -std=c++11 or -std=c++0x when compiling - both these solutions did not work. Another solution suggested a bug in the compiler version but it's not the compiler I am using I do not think. I am using g++ (GCC) 5.0.0 20141005 (experimental) version on a 64x Apple Macbook Pro.
Usage of stoi() and to_string() in this part of code is pretty weird, and completely unnecessary. You can simply write
int w = weights[i] - out * weights[i];
To use std::stoi() and std::to_string() you need to have a proper
#include <string>
statement, and the c++11 language options set (see the links to the documentation reference above).
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
I have recently worked on C, but I have started to study C++. I had a homework in to create a program that would read texts and organize data out of the imputed text. This is the last part I have left, but I don't get what's wrong with my code. This part of the problem is pretty simple, but I still don't understand what my errors are. I got used to gcc compiler which wrote mostly segmentation fault, but g++ compiler errors are different. Any tips or hints on what to pay more attention while transferring from c to c++ would be really appreciated.
This is my output errors.
-bash-3.2$ g++ -o Printfunction Printfunction.cpp
Printfunction.cpp: In function 'void Printfunction(wordList*)':
Printfunction.cpp:43: error: cannot convert 'NumberList*' to 'Numberlist*' for argument '1' to 'std::string returnlist(Numberlist*)'
Printfunction.cpp: In function 'std::string returnlist(Numberlist*)':
Printfunction.cpp:56: error: invalid use of undefined type 'struct Numberlist'
Printfunction.cpp:10: error: forward declaration of 'struct Numberlist'
Printfunction.cpp:56: error: 'to_string' was not declared in this scope
Printfunction.cpp:57: error: invalid use of undefined type 'struct Numberlist'
Printfunction.cpp:10: error: forward declaration of 'struct Numberlist'
Can you please tell me what's wrong with my code?
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
struct NumberList
{
int line;
struct Numberlist *nextPtr;
};
struct wordList
{
string word;
int Count;
NumberList lines;
struct wordList *nextPtr;
};
void Printfunction(wordList *list);
string returnlist(Numberlist *list);
int main()
{
wordList something;
something.word = "SOMETHING";
something.Count = 55555;
something.nextPtr = NULL;
Printfunction(&something);
}
void Printfunction(wordList *list)
{
int i;
i=1;
cout<<"+----+----------------------------+-------+---------------------------------+"<<endl;
cout<<"|# | WORD | COUNT | LINES |"<<endl;
cout<<"+----+----------------------------+-------+---------------------------------+"<<endl;
while(list != NULL)
{
cout<<"|"<<left<<setw(4)<<i<<"|"<<left<<setw(28)<<list->word<<"|"<<left<<setw(7)<<list->Count<<"|"<<left<<setw(33)<<returnlist(&(list->lines))<<"|"<<endl;
cout<<"+----+----------------------------+-------+---------------------------------+"<<endl;
list = list->nextPtr;
i++;
}
}
string returnlist(Numberlist *list)
{
string final;
while(list != NULL)
{
final.append(", ");
final.append(to_string(list->line));
list = list->nextPtr;
}
final.append(".");
return final;
}
The problem is that sometimes you spell it NumberList, and sometimes you spell it Numberlist.
Any tips or hints on what to pay more attention
Case matters.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
First of all here is my C++ source:
#include <iostream>
using namespace std;
void number(int x){
cout << "Number is: " << x << endl;
}
int main(){
cin >> int x;
number(x);
return(0);
}
Upon compiling I get the following errors:
file.cpp: In function 'int main()':
file.cpp:9:9: error: expected primary-expressing before 'int'
file.cpp:9:9: error: expected ';' before 'int'
file.cpp:10:9: error: 'x' was not declared in this scope
I compile and run this successfully in CodeBlocks but under Ubuntu with gcc or g++ things fail.
Change
int main(){
cin >> int x;
to
int main(){
int x;
cin >> x;